From e476a1fe0d9408275043082d4f981fc6fb0bba78 Mon Sep 17 00:00:00 2001 From: Stuart Kuentzel Date: Thu, 16 Jun 2022 14:24:41 +0900 Subject: [PATCH 01/13] adds gateway fee method to lockup --- .vscode/settings.json | 3 +- contracts/interface/ILockup.sol | 4 ++ contracts/src/lockup/Lockup.sol | 71 +++++++++++++++++++++----- package.json | 6 +-- test/lockup/lockup-s-token-scenario.ts | 55 ++++++++++++++++++++ 5 files changed, 121 insertions(+), 18 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a2f9328f..744ac11d 100755 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,5 +12,6 @@ ], "editor.codeActionsOnSave": { "source.fixAll.eslint": true - } + }, + "solidity.compileUsingRemoteVersion": "v0.8.9+commit.e5eed63a" } diff --git a/contracts/interface/ILockup.sol b/contracts/interface/ILockup.sol index 08854749..8b7c65c9 100644 --- a/contracts/interface/ILockup.sol +++ b/contracts/interface/ILockup.sol @@ -35,6 +35,10 @@ interface ILockup { external returns (uint256); + function gatedDepositToProperty(address _property, uint256 _amount, address _gatewayAddress, uint256 _gatewayFee) + external + returns (uint256); + function depositToPosition(uint256 _tokenId, uint256 _amount) external returns (bool); diff --git a/contracts/src/lockup/Lockup.sol b/contracts/src/lockup/Lockup.sol index 8b31875d..9cc2081f 100644 --- a/contracts/src/lockup/Lockup.sol +++ b/contracts/src/lockup/Lockup.sol @@ -99,21 +99,9 @@ contract Lockup is ILockup, InitializableUsingRegistry { } /** - * @dev deposit dev token to dev protocol and generate s-token - * @param _property target property address - * @param _amount staking value - * @return tokenId The ID of the created new staking position + * */ - function depositToProperty(address _property, uint256 _amount) - external - override - onlyAuthenticatedProperty(_property) - returns (uint256) - { - /** - * Validates _amount is not 0. - */ - require(_amount != 0, "illegal deposit amount"); + function _deposit(address _property, uint256 _amount) private returns (uint256) { /** * Gets the latest cumulative sum of the interest price. */ @@ -163,6 +151,61 @@ contract Lockup is ILockup, InitializableUsingRegistry { return tokenId; } + /** + * @dev deposit dev token to dev protocol and generate s-token + * @param _property target property address + * @param _amount staking value + * @return tokenId The ID of the created new staking position + */ + function depositToProperty(address _property, uint256 _amount) + external + override + onlyAuthenticatedProperty(_property) + returns (uint256) + { + /** + * Validates _amount is not 0. + */ + require(_amount != 0, "illegal deposit amount"); + + return _deposit(_property, _amount); + } + + /** + * @dev deposit dev token to dev protocol and generate s-token + * @param _property target property address + * @param _amount staking value + * @param _gatewayAddress is the address to which the liquidity provider fee will be directed + * @param _gatewayFee is the basis points to pass. For example 10000 is 100% + * @return tokenId The ID of the created new staking position + */ + function gatedDepositToProperty(address _property, uint256 _amount, address _gatewayAddress, uint256 _gatewayFee) + external + onlyAuthenticatedProperty(_property) + returns (uint256) + { + /** + * Validates _amount is not 0. + */ + require(_amount != 0, "illegal deposit amount"); + + uint256 feeAmount = _amount * _gatewayFee / 10000; + + /** + * transfer feeAmount to _gatewayAddress + */ + require( + IERC20(registry().registries("Dev")).transferFrom( + msg.sender, + _gatewayAddress, + feeAmount + ), + "dev transfer failed" + ); + + return _deposit(_property, _amount - feeAmount); + } + /** * @dev deposit dev token to dev protocol and update s-token status * @param _tokenId s-token id diff --git a/package.json b/package.json index c21ad2cd..6c37271c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devprotocol/protocol-v2", - "version": "0.5.0", + "version": "0.5.1", "description": "Securitize for Internet assets", "scripts": { "test": "truffle test --config truffle-config.js", @@ -42,6 +42,7 @@ "eslint-config-xo": "0.41.0", "eslint-config-xo-typescript": "0.51.1", "husky": "7.0.4", + "js-base64": "3.7.2", "p-queue": "7.2.0", "prettier": "2.7.0", "prettier-plugin-solidity": "1.0.0-beta.19", @@ -55,8 +56,7 @@ "typechain-target-truffle": "1.0.2", "typescript": "4.7.3", "web3": "1.7.3", - "web3-utils": "1.7.3", - "js-base64": "3.7.2" + "web3-utils": "1.7.3" }, "dependencies": { "@devprotocol/util-contracts": "3.3.0", diff --git a/test/lockup/lockup-s-token-scenario.ts b/test/lockup/lockup-s-token-scenario.ts index d5a117f7..9efc945a 100644 --- a/test/lockup/lockup-s-token-scenario.ts +++ b/test/lockup/lockup-s-token-scenario.ts @@ -1116,6 +1116,61 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { expect(bobAmount.toFixed()).to.be.equal(expected) }) }) + + describe('scenario; single lockup with gateway fee', () => { + let dev: DevProtocolInstance + let property: PropertyInstance + let lastTimestamp: number + + const alice = deployer + const bob = user1 + + const aliceFirstTokenId = 1 + + before(async () => { + ;[dev, property] = await init(deployer, user2) + const aliceBalance = await dev.dev.balanceOf(alice).then(toBigNumber) + await dev.dev.approve(dev.lockup.address, aliceBalance, { + from: alice, + }) + + lastTimestamp = await getBlockTimestamp() + }) + + /* + * PolicyTestBase returns 100 as rewards + * And stakers share is 10% + */ + + it(`Alice should deposit to property and send Bob a gateway fee`, async () => { + const basisPoints = 300 // 3% + const depositAmount = 10000 + const gatewayAddress = bob + + await dev.lockup.gatedDepositToProperty( + property.address, + depositAmount, + gatewayAddress, + basisPoints, + { + from: alice, + } + ) + + const bobBalance = await dev.dev.balanceOf(bob).then(toBigNumber) + + /** + * Bob should get his gateway fee + */ + expect(bobBalance.toNumber()).to.be.equal( + (depositAmount * basisPoints) / 10000 + ) + + /** + * TODO - Alice should have (amount - fee) locked up + */ + }) + }) }) }) }) From f288fa0f5300bfdd4c70303f3211f77443a6f8ca Mon Sep 17 00:00:00 2001 From: Stuart Kuentzel Date: Thu, 16 Jun 2022 14:25:13 +0900 Subject: [PATCH 02/13] linting --- contracts/interface/ILockup.sol | 9 ++++++--- contracts/src/lockup/Lockup.sol | 18 +++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/contracts/interface/ILockup.sol b/contracts/interface/ILockup.sol index 8b7c65c9..66271452 100644 --- a/contracts/interface/ILockup.sol +++ b/contracts/interface/ILockup.sol @@ -35,9 +35,12 @@ interface ILockup { external returns (uint256); - function gatedDepositToProperty(address _property, uint256 _amount, address _gatewayAddress, uint256 _gatewayFee) - external - returns (uint256); + function gatedDepositToProperty( + address _property, + uint256 _amount, + address _gatewayAddress, + uint256 _gatewayFee + ) external returns (uint256); function depositToPosition(uint256 _tokenId, uint256 _amount) external diff --git a/contracts/src/lockup/Lockup.sol b/contracts/src/lockup/Lockup.sol index 9cc2081f..01b28df7 100644 --- a/contracts/src/lockup/Lockup.sol +++ b/contracts/src/lockup/Lockup.sol @@ -101,7 +101,10 @@ contract Lockup is ILockup, InitializableUsingRegistry { /** * */ - function _deposit(address _property, uint256 _amount) private returns (uint256) { + function _deposit(address _property, uint256 _amount) + private + returns (uint256) + { /** * Gets the latest cumulative sum of the interest price. */ @@ -179,17 +182,18 @@ contract Lockup is ILockup, InitializableUsingRegistry { * @param _gatewayFee is the basis points to pass. For example 10000 is 100% * @return tokenId The ID of the created new staking position */ - function gatedDepositToProperty(address _property, uint256 _amount, address _gatewayAddress, uint256 _gatewayFee) - external - onlyAuthenticatedProperty(_property) - returns (uint256) - { + function gatedDepositToProperty( + address _property, + uint256 _amount, + address _gatewayAddress, + uint256 _gatewayFee + ) external onlyAuthenticatedProperty(_property) returns (uint256) { /** * Validates _amount is not 0. */ require(_amount != 0, "illegal deposit amount"); - uint256 feeAmount = _amount * _gatewayFee / 10000; + uint256 feeAmount = (_amount * _gatewayFee) / 10000; /** * transfer feeAmount to _gatewayAddress From dd7dc701d8f528870cf9d0ba7c2ffb7a554c5016 Mon Sep 17 00:00:00 2001 From: Stuart Kuentzel Date: Fri, 17 Jun 2022 14:08:07 +0900 Subject: [PATCH 03/13] ensure gateway fee is below 100% --- contracts/src/lockup/Lockup.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/src/lockup/Lockup.sol b/contracts/src/lockup/Lockup.sol index 01b28df7..bdb03908 100644 --- a/contracts/src/lockup/Lockup.sol +++ b/contracts/src/lockup/Lockup.sol @@ -192,6 +192,7 @@ contract Lockup is ILockup, InitializableUsingRegistry { * Validates _amount is not 0. */ require(_amount != 0, "illegal deposit amount"); + require(_gatewayFee <= 10000, "must be below 10000"); uint256 feeAmount = (_amount * _gatewayFee) / 10000; From 1e97251979899924c0c549efefae011f57f276ac Mon Sep 17 00:00:00 2001 From: Stuart <11183054+stuartwk@users.noreply.github.com> Date: Mon, 20 Jun 2022 05:10:29 +0000 Subject: [PATCH 04/13] property minus fee staking passes --- test/lockup/lockup-s-token-scenario.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/lockup/lockup-s-token-scenario.ts b/test/lockup/lockup-s-token-scenario.ts index 9efc945a..4d203449 100644 --- a/test/lockup/lockup-s-token-scenario.ts +++ b/test/lockup/lockup-s-token-scenario.ts @@ -1158,17 +1158,23 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { ) const bobBalance = await dev.dev.balanceOf(bob).then(toBigNumber) + const feeAmount = (depositAmount * basisPoints) / 10000; /** * Bob should get his gateway fee */ - expect(bobBalance.toNumber()).to.be.equal( - (depositAmount * basisPoints) / 10000 - ) + expect(bobBalance.toNumber()).to.be.equal(feeAmount) /** - * TODO - Alice should have (amount - fee) locked up + * Alice should have (amount - fee) locked up */ + const propertyPosition = await dev.sTokensManager.positions( + aliceFirstTokenId + ) + const propertyBalance = toBigNumber( + propertyPosition.amount + ) + expect(propertyBalance.toNumber()).to.eq(new BigNumber(depositAmount).minus(feeAmount).toNumber()); }) }) }) From d8322245f56b69c7a13b06680b18baf41dd4a263 Mon Sep 17 00:00:00 2001 From: Stuart <11183054+stuartwk@users.noreply.github.com> Date: Mon, 20 Jun 2022 05:11:07 +0000 Subject: [PATCH 05/13] linted --- test/lockup/lockup-s-token-scenario.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/lockup/lockup-s-token-scenario.ts b/test/lockup/lockup-s-token-scenario.ts index 4d203449..386619d3 100644 --- a/test/lockup/lockup-s-token-scenario.ts +++ b/test/lockup/lockup-s-token-scenario.ts @@ -1158,7 +1158,7 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { ) const bobBalance = await dev.dev.balanceOf(bob).then(toBigNumber) - const feeAmount = (depositAmount * basisPoints) / 10000; + const feeAmount = (depositAmount * basisPoints) / 10000 /** * Bob should get his gateway fee @@ -1171,10 +1171,10 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { const propertyPosition = await dev.sTokensManager.positions( aliceFirstTokenId ) - const propertyBalance = toBigNumber( - propertyPosition.amount + const propertyBalance = toBigNumber(propertyPosition.amount) + expect(propertyBalance.toNumber()).to.eq( + new BigNumber(depositAmount).minus(feeAmount).toNumber() ) - expect(propertyBalance.toNumber()).to.eq(new BigNumber(depositAmount).minus(feeAmount).toNumber()); }) }) }) From 31e72368ebb3820674423d0becbc694ac65ba7ad Mon Sep 17 00:00:00 2001 From: Stuart <11183054+stuartwk@users.noreply.github.com> Date: Mon, 20 Jun 2022 06:18:40 +0000 Subject: [PATCH 06/13] renames _deposit -> _depositToProperty --- contracts/src/lockup/Lockup.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/src/lockup/Lockup.sol b/contracts/src/lockup/Lockup.sol index bdb03908..721a06a3 100644 --- a/contracts/src/lockup/Lockup.sol +++ b/contracts/src/lockup/Lockup.sol @@ -101,7 +101,7 @@ contract Lockup is ILockup, InitializableUsingRegistry { /** * */ - function _deposit(address _property, uint256 _amount) + function _depositToProperty(address _property, uint256 _amount) private returns (uint256) { @@ -171,7 +171,7 @@ contract Lockup is ILockup, InitializableUsingRegistry { */ require(_amount != 0, "illegal deposit amount"); - return _deposit(_property, _amount); + return _depositToProperty(_property, _amount); } /** @@ -208,7 +208,7 @@ contract Lockup is ILockup, InitializableUsingRegistry { "dev transfer failed" ); - return _deposit(_property, _amount - feeAmount); + return _depositToProperty(_property, _amount - feeAmount); } /** From 8b7b638f3d13ecc35499938856e152aea040f840 Mon Sep 17 00:00:00 2001 From: Stuart <11183054+stuartwk@users.noreply.github.com> Date: Tue, 21 Jun 2022 02:06:25 +0000 Subject: [PATCH 07/13] withdraw fee and basic test --- contracts/interface/ILockup.sol | 7 ++ contracts/src/lockup/Lockup.sol | 101 ++++++++++++++++++++----- test/lockup/lockup-s-token-scenario.ts | 65 ++++++++++++++++ 3 files changed, 154 insertions(+), 19 deletions(-) diff --git a/contracts/interface/ILockup.sol b/contracts/interface/ILockup.sol index 66271452..0727c9e6 100644 --- a/contracts/interface/ILockup.sol +++ b/contracts/interface/ILockup.sol @@ -53,6 +53,13 @@ interface ILockup { function update() external; + function withdrawByPosition( + uint256 _tokenId, + uint256 _amount, + address _gatewayAddress, + uint256 _gatewayBasisFee + ) external returns (bool); + function withdrawByPosition(uint256 _tokenId, uint256 _amount) external returns (bool); diff --git a/contracts/src/lockup/Lockup.sol b/contracts/src/lockup/Lockup.sol index 721a06a3..51df1a92 100644 --- a/contracts/src/lockup/Lockup.sol +++ b/contracts/src/lockup/Lockup.sol @@ -276,15 +276,20 @@ contract Lockup is ILockup, InitializableUsingRegistry { } /** - * Withdraw staking.(NFT) + * @dev Withdraw staking.(NFT) * Releases staking, withdraw rewards, and transfer the staked and withdraw rewards amount to the sender. + * @param _tokenId s-token id + * @param _amount staking value + * @param _gatewayAddress optional gateway fee address - set address(0) for no fee + * @param _gatewayBasisFee is the basis points fee. For example 10000 is a 100% fee + * @return bool On success, true will be returned */ - function withdrawByPosition(uint256 _tokenId, uint256 _amount) - external - override - onlyPositionOwner(_tokenId) - returns (bool) - { + function _withdrawByPosition( + uint256 _tokenId, + uint256 _amount, + address _gatewayAddress, + uint256 _gatewayBasisFee + ) private returns (bool) { ISTokensManager sTokenManager = ISTokensManager( registry().registries("STokensManager") ); @@ -301,7 +306,9 @@ contract Lockup is ILockup, InitializableUsingRegistry { * Withdraws the staking reward */ (uint256 value, RewardPrices memory prices) = _withdrawInterest( - positions + positions, + _gatewayAddress, + _gatewayBasisFee ); /** * Transfer the staked amount to the sender. @@ -313,7 +320,6 @@ contract Lockup is ILockup, InitializableUsingRegistry { * Saves variables that should change due to the canceling staking.. */ updateValues(false, positions.property, _amount, prices); - uint256 cumulative = positions.cumulativeReward + value; /** * update position information @@ -322,7 +328,7 @@ contract Lockup is ILockup, InitializableUsingRegistry { _tokenId, positions.amount - _amount, prices.interest, - cumulative, + positions.cumulativeReward + value, 0 ); if (totalLockedForProperty[positions.property] == 0) { @@ -336,6 +342,45 @@ contract Lockup is ILockup, InitializableUsingRegistry { return result; } + /** + * @dev Withdraw staking.(NFT) + * Releases staking, withdraw rewards, and transfer the staked and withdraw rewards amount to the sender. + * @param _tokenId s-token id + * @param _amount staking value + * @return bool On success, true will be returned + */ + function withdrawByPosition(uint256 _tokenId, uint256 _amount) + external + override + onlyPositionOwner(_tokenId) + returns (bool) + { + return _withdrawByPosition(_tokenId, _amount, address(0), 0); + } + + /** + * @dev withdrawByPosition overloaded with _gatewayAddress and _gatewayBasisFee + * @param _tokenId s-token id + * @param _amount staking value + * @param _gatewayAddress optional gateway fee address - set address(0) for no fee + * @param _gatewayBasisFee is the basis points fee. For example 10000 is a 100% fee + * @return bool On success, true will be returned + */ + function withdrawByPosition( + uint256 _tokenId, + uint256 _amount, + address _gatewayAddress, + uint256 _gatewayBasisFee + ) external override onlyPositionOwner(_tokenId) returns (bool) { + return + _withdrawByPosition( + _tokenId, + _amount, + _gatewayAddress, + _gatewayBasisFee + ); + } + /** * get lockup info */ @@ -706,7 +751,9 @@ contract Lockup is ILockup, InitializableUsingRegistry { * Withdraws staking reward as an interest. */ function _withdrawInterest( - ISTokensManager.StakingPositions memory positions + ISTokensManager.StakingPositions memory positions, + address _gatewayAddress, + uint256 _gatewayBasisFee ) private returns (uint256 value_, RewardPrices memory prices_) { /** * Gets the withdrawable amount. @@ -716,16 +763,32 @@ contract Lockup is ILockup, InitializableUsingRegistry { RewardPrices memory prices ) = _calculateWithdrawableInterestAmount(positions); + IDevBridge devBridge = IDevBridge(registry().registries("DevBridge")); + /** - * Mints the reward. + * Gateway Fee exists + * send fee to gateway address and the remainder to msg.sender */ - require( - IDevBridge(registry().registries("DevBridge")).mint( - msg.sender, - value - ), - "dev mint failed" - ); + if (_gatewayAddress != address(0) && _gatewayBasisFee > 0) { + uint256 feeValue = (value * _gatewayBasisFee) / 10000; + + require( + devBridge.mint(msg.sender, value - feeValue), + "dev mint failed" + ); + + require( + devBridge.mint(_gatewayAddress, feeValue), + "fee dev mint failed" + ); + } + /** + * No gateway fee + * send the entirety to msg.sender + */ + else { + require(devBridge.mint(msg.sender, value), "dev mint failed"); + } /** * Since the total supply of tokens has changed, updates the latest maximum mint amount. diff --git a/test/lockup/lockup-s-token-scenario.ts b/test/lockup/lockup-s-token-scenario.ts index 386619d3..4935cdde 100644 --- a/test/lockup/lockup-s-token-scenario.ts +++ b/test/lockup/lockup-s-token-scenario.ts @@ -1177,6 +1177,71 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { ) }) }) + + + + describe('scenario; gateway fees', () => { + let dev: DevProtocolInstance + let property: PropertyInstance + let lastTimestamp: number + + const alice = deployer + const bob = user1 + const depositAmount = 10000; + + const aliceFirstTokenId = 1 + + before(async () => { + ;[dev, property] = await init(deployer, user2) + const aliceBalance = await dev.dev.balanceOf(alice).then(toBigNumber) + await dev.dev.mint(bob, aliceBalance) + await dev.dev.approve(dev.lockup.address, aliceBalance, { from: alice }) + await dev.lockup.depositToProperty(property.address, depositAmount, { + from: alice, + }) + + lastTimestamp = await getBlockTimestamp() + }) + + it(`Alice's withdrawable interest is 100% of the Property's interest`, async () => { + + await forwardBlockTimestamp(9) + + const beforeAliceBalance = await dev.dev + .balanceOf(alice) + .then(toBigNumber) + + const beforeBobBalance = await dev.dev + .balanceOf(bob) + .then(toBigNumber) + + const t1 = await getBlockTimestamp() + const gatewayBasisFee = 300 // 3% + const expected = toBigNumber(10) // In PolicyTestBase, the max staker reward per block is 10. + .times(1e18) + .times(t1 - lastTimestamp) + + const feeAmount = expected.toNumber() * gatewayBasisFee / 10000; + const expectedMinusFee = expected.minus(feeAmount) + const position = await dev.sTokensManager.positions(aliceFirstTokenId) + const aliceLocked = toBigNumber(position.amount) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['withdrawByPosition(uint256,uint256,address,uint256)'](aliceFirstTokenId, aliceLocked, bob, gatewayBasisFee, { from: alice }) + + const afterAliceBalance = await dev.dev + .balanceOf(alice) + .then(toBigNumber) + + const afterBobBalance = await dev.dev + .balanceOf(bob) + .then(toBigNumber) + + expect(afterAliceBalance.toNumber()).to.eq(beforeAliceBalance.plus(expectedMinusFee).toNumber()) + expect(afterBobBalance.toNumber()).to.eq(beforeBobBalance.plus(feeAmount).toNumber()) + }) + }) }) }) }) From 8673d55e545e344cfdb2633a9a49190cb48c4056 Mon Sep 17 00:00:00 2001 From: Stuart <11183054+stuartwk@users.noreply.github.com> Date: Tue, 21 Jun 2022 02:07:06 +0000 Subject: [PATCH 08/13] linting --- test/lockup/lockup-s-token-scenario.ts | 39 +++++++++++++++----------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/test/lockup/lockup-s-token-scenario.ts b/test/lockup/lockup-s-token-scenario.ts index 4935cdde..2878cb3d 100644 --- a/test/lockup/lockup-s-token-scenario.ts +++ b/test/lockup/lockup-s-token-scenario.ts @@ -1178,33 +1178,32 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { }) }) - - describe('scenario; gateway fees', () => { let dev: DevProtocolInstance let property: PropertyInstance let lastTimestamp: number - + const alice = deployer const bob = user1 - const depositAmount = 10000; - + const depositAmount = 10000 + const aliceFirstTokenId = 1 - + before(async () => { ;[dev, property] = await init(deployer, user2) const aliceBalance = await dev.dev.balanceOf(alice).then(toBigNumber) await dev.dev.mint(bob, aliceBalance) - await dev.dev.approve(dev.lockup.address, aliceBalance, { from: alice }) + await dev.dev.approve(dev.lockup.address, aliceBalance, { + from: alice, + }) await dev.lockup.depositToProperty(property.address, depositAmount, { from: alice, }) - + lastTimestamp = await getBlockTimestamp() }) - - it(`Alice's withdrawable interest is 100% of the Property's interest`, async () => { + it(`Alice's withdrawable interest is 100% of the Property's interest`, async () => { await forwardBlockTimestamp(9) const beforeAliceBalance = await dev.dev @@ -1221,25 +1220,31 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { .times(1e18) .times(t1 - lastTimestamp) - const feeAmount = expected.toNumber() * gatewayBasisFee / 10000; + const feeAmount = (expected.toNumber() * gatewayBasisFee) / 10000 const expectedMinusFee = expected.minus(feeAmount) const position = await dev.sTokensManager.positions(aliceFirstTokenId) const aliceLocked = toBigNumber(position.amount) // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods['withdrawByPosition(uint256,uint256,address,uint256)'](aliceFirstTokenId, aliceLocked, bob, gatewayBasisFee, { from: alice }) + await dev.lockup.methods[ + 'withdrawByPosition(uint256,uint256,address,uint256)' + ](aliceFirstTokenId, aliceLocked, bob, gatewayBasisFee, { + from: alice, + }) const afterAliceBalance = await dev.dev .balanceOf(alice) .then(toBigNumber) - const afterBobBalance = await dev.dev - .balanceOf(bob) - .then(toBigNumber) + const afterBobBalance = await dev.dev.balanceOf(bob).then(toBigNumber) - expect(afterAliceBalance.toNumber()).to.eq(beforeAliceBalance.plus(expectedMinusFee).toNumber()) - expect(afterBobBalance.toNumber()).to.eq(beforeBobBalance.plus(feeAmount).toNumber()) + expect(afterAliceBalance.toNumber()).to.eq( + beforeAliceBalance.plus(expectedMinusFee).toNumber() + ) + expect(afterBobBalance.toNumber()).to.eq( + beforeBobBalance.plus(feeAmount).toNumber() + ) }) }) }) From 17f5e995f4c874426804b4c824d9f633bdaa01ec Mon Sep 17 00:00:00 2001 From: Stuart <11183054+stuartwk@users.noreply.github.com> Date: Tue, 21 Jun 2022 04:58:06 +0000 Subject: [PATCH 09/13] overload depositToProperty; updates tests --- contracts/interface/ILockup.sol | 2 +- contracts/src/lockup/Lockup.sol | 46 +++--- test/lockup/lockup-s-token-common.ts | 9 +- test/lockup/lockup-s-token-scenario.ts | 211 +++++++++++++++++++------ test/lockup/lockup-s-token.ts | 142 ++++++++++++++--- test/lockup/lockup.ts | 6 +- 6 files changed, 321 insertions(+), 95 deletions(-) diff --git a/contracts/interface/ILockup.sol b/contracts/interface/ILockup.sol index 0727c9e6..c50ff23e 100644 --- a/contracts/interface/ILockup.sol +++ b/contracts/interface/ILockup.sol @@ -35,7 +35,7 @@ interface ILockup { external returns (uint256); - function gatedDepositToProperty( + function depositToProperty( address _property, uint256 _amount, address _gatewayAddress, diff --git a/contracts/src/lockup/Lockup.sol b/contracts/src/lockup/Lockup.sol index 51df1a92..917c6ec3 100644 --- a/contracts/src/lockup/Lockup.sol +++ b/contracts/src/lockup/Lockup.sol @@ -155,39 +155,19 @@ contract Lockup is ILockup, InitializableUsingRegistry { } /** - * @dev deposit dev token to dev protocol and generate s-token - * @param _property target property address - * @param _amount staking value - * @return tokenId The ID of the created new staking position - */ - function depositToProperty(address _property, uint256 _amount) - external - override - onlyAuthenticatedProperty(_property) - returns (uint256) - { - /** - * Validates _amount is not 0. - */ - require(_amount != 0, "illegal deposit amount"); - - return _depositToProperty(_property, _amount); - } - - /** - * @dev deposit dev token to dev protocol and generate s-token + * @dev overloaded depositToProperty with gateway fee params * @param _property target property address * @param _amount staking value * @param _gatewayAddress is the address to which the liquidity provider fee will be directed * @param _gatewayFee is the basis points to pass. For example 10000 is 100% * @return tokenId The ID of the created new staking position */ - function gatedDepositToProperty( + function depositToProperty( address _property, uint256 _amount, address _gatewayAddress, uint256 _gatewayFee - ) external onlyAuthenticatedProperty(_property) returns (uint256) { + ) external override onlyAuthenticatedProperty(_property) returns (uint256) { /** * Validates _amount is not 0. */ @@ -211,6 +191,26 @@ contract Lockup is ILockup, InitializableUsingRegistry { return _depositToProperty(_property, _amount - feeAmount); } + /** + * @dev deposit dev token to dev protocol and generate s-token + * @param _property target property address + * @param _amount staking value + * @return tokenId The ID of the created new staking position + */ + function depositToProperty(address _property, uint256 _amount) + external + override + onlyAuthenticatedProperty(_property) + returns (uint256) + { + /** + * Validates _amount is not 0. + */ + require(_amount != 0, "illegal deposit amount"); + + return _depositToProperty(_property, _amount); + } + /** * @dev deposit dev token to dev protocol and update s-token status * @param _tokenId s-token id diff --git a/test/lockup/lockup-s-token-common.ts b/test/lockup/lockup-s-token-common.ts index 4ec2fdf2..d507ad01 100644 --- a/test/lockup/lockup-s-token-common.ts +++ b/test/lockup/lockup-s-token-common.ts @@ -55,7 +55,14 @@ export const init2 = async ( ): Promise<[DevProtocolInstance, PropertyInstance, number]> => { const [dev, property] = await init(deployer, user) await dev.dev.approve(dev.lockup.address, 600) - await dev.lockup.depositToProperty(property.address, 100) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 100 + ) + const tokenIds = await dev.sTokensManager.positionsOfOwner(deployer) return [dev, property, tokenIds[0].toNumber()] diff --git a/test/lockup/lockup-s-token-scenario.ts b/test/lockup/lockup-s-token-scenario.ts index 2878cb3d..706c9c05 100644 --- a/test/lockup/lockup-s-token-scenario.ts +++ b/test/lockup/lockup-s-token-scenario.ts @@ -64,9 +64,16 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { * And stakers share is 10% */ it('Alice has a 100% of interests', async () => { - await dev.lockup.depositToProperty(property.address, 1000000000000, { - from: alice, - }) + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 1000000000000, + { + from: alice, + } + ) + const t1 = await getBlockTimestamp() await forwardBlockTimestamp(1) @@ -101,9 +108,15 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { expect(result.toFixed()).to.be.equal(calculated) }) it('Alice has a 50% of interests', async () => { - await dev.lockup.depositToProperty(property.address, 1000000000000, { - from: bob, - }) + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 1000000000000, + { + from: bob, + } + ) timestamps.set('a1', await getBlockTimestamp()) await dev.lockup.withdrawByPosition(aliceFirstTokenId, 0, { from: alice, @@ -237,9 +250,16 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { bobPosition.amount.toString(), { from: bob } ) - await dev.lockup.depositToProperty(property.address, 1000000000000, { - from: alice, - }) + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 1000000000000, + { + from: alice, + } + ) + const t1 = await getBlockTimestamp() await forwardBlockTimestamp(1) const result = await dev.lockup @@ -258,9 +278,17 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { await dev.lockup.depositToPosition(aliceSecoundTokenId, 1000000000000, { from: alice, }) - await dev.lockup.depositToProperty(property.address, 1000000000000, { - from: bob, - }) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 1000000000000, + { + from: bob, + } + ) + await forwardBlockTimestamp(2) const alicePosition = await dev.sTokensManager.positions( aliceSecoundTokenId @@ -311,14 +339,29 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { const bobBalance = toBigNumber(10000000).times(1e18) await dev.dev.mint(bob, bobBalance) - await dev.lockup.depositToProperty(property.address, bobBalance, { - from: bob, - }) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + bobBalance, + { + from: bob, + } + ) + await forwardBlockTimestamp(10) - await dev.lockup.depositToProperty(property2.address, 10000000, { - from: alice, - }) + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property2.address, + 10000000, + { + from: alice, + } + ) + const t1 = await getBlockTimestamp() await forwardBlockTimestamp(1) const result = await dev.lockup @@ -344,9 +387,17 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { propertyAddress, 1 ) - await dev.lockup.depositToProperty(propertyAddress, 1000000000000, { - from: alice, - }) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + propertyAddress, + 1000000000000, + { + from: alice, + } + ) + await forwardBlockTimestamp(1) await dev.lockup.depositToPosition(aliceFourthTokenId, 1000000000000, { from: alice, @@ -380,9 +431,16 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { const aliceBalance = await dev.dev.balanceOf(alice).then(toBigNumber) await dev.dev.mint(bob, aliceBalance) await dev.dev.approve(dev.lockup.address, aliceBalance, { from: alice }) - await dev.lockup.depositToProperty(property.address, 10000, { - from: alice, - }) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 10000, + { + from: alice, + } + ) lastTimestamp = await getBlockTimestamp() }) @@ -495,9 +553,16 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { const aliceBalance = await dev.dev.balanceOf(alice).then(toBigNumber) await dev.dev.mint(bob, aliceBalance) await dev.dev.approve(dev.lockup.address, aliceBalance, { from: alice }) - await dev.lockup.depositToProperty(property.address, 10000, { - from: alice, - }) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 10000, + { + from: alice, + } + ) lastTimestamp = await getBlockTimestamp() }) @@ -616,9 +681,16 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { await dev.dev.mint(bob, aliceBalance) await dev.dev.approve(dev.lockup.address, aliceBalance, { from: alice }) await dev.dev.approve(dev.lockup.address, aliceBalance, { from: bob }) - await dev.lockup.depositToProperty(property.address, 10000, { - from: alice, - }) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 10000, + { + from: alice, + } + ) }) describe('before second run', () => { @@ -631,9 +703,16 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { expect(aliceBalance.toFixed()).to.be.equal(total.toFixed()) }) it(`Bob does staking 25% of the Property's total lockups, Alice's share become 80%`, async () => { - await dev.lockup.depositToProperty(property.address, 10000 * 0.25, { - from: bob, - }) + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 10000 * 0.25, + { + from: bob, + } + ) + const total = await dev.lockup .totalLockedForProperty(property.address) .then(toBigNumber) @@ -845,9 +924,16 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { 1 ) - await dev.lockup.depositToProperty(property1.address, 10000, { - from: alice, - }) + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property1.address, + 10000, + { + from: alice, + } + ) + await forwardBlockTimestamp(3) }) @@ -861,9 +947,16 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { expect(aliceBalance.toFixed()).to.be.equal(total.toFixed()) }) it(`Bob does staking 100% of the Property2 total lockups, Property2 is 20% of the total rewards`, async () => { - await dev.lockup.depositToProperty(property2.address, 2500, { - from: bob, - }) + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property2.address, + 2500, + { + from: bob, + } + ) + const total = await dev.lockup.totalLocked().then(toBigNumber) const p1 = await dev.lockup .totalLockedForProperty(property1.address) @@ -973,9 +1066,16 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { }) describe('additional staking', () => { before(async () => { - await dev.lockup.depositToProperty(property3.address, 16250 * 0.6, { - from: alice, - }) + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property3.address, + 16250 * 0.6, + { + from: alice, + } + ) + await forwardBlockTimestamp(3) }) it(`Alice does staking 60% of the all Property's total lockups, Alice's share become ${ @@ -1147,7 +1247,7 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { const depositAmount = 10000 const gatewayAddress = bob - await dev.lockup.gatedDepositToProperty( + await dev.lockup.depositToProperty( property.address, depositAmount, gatewayAddress, @@ -1178,7 +1278,7 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { }) }) - describe('scenario; gateway fees', () => { + describe('scenario; gateway fees withdraw', () => { let dev: DevProtocolInstance let property: PropertyInstance let lastTimestamp: number @@ -1196,9 +1296,19 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { await dev.dev.approve(dev.lockup.address, aliceBalance, { from: alice, }) - await dev.lockup.depositToProperty(property.address, depositAmount, { - from: alice, - }) + // Await dev.lockup.depositToProperty(property.address, depositAmount, { + // from: alice, + // }) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + depositAmount, + { + from: alice, + } + ) lastTimestamp = await getBlockTimestamp() }) @@ -1214,6 +1324,8 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { .balanceOf(bob) .then(toBigNumber) + console.log('beforeBobBalance: ', beforeBobBalance.toNumber()) + const t1 = await getBlockTimestamp() const gatewayBasisFee = 300 // 3% const expected = toBigNumber(10) // In PolicyTestBase, the max staker reward per block is 10. @@ -1221,6 +1333,9 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { .times(t1 - lastTimestamp) const feeAmount = (expected.toNumber() * gatewayBasisFee) / 10000 + + console.log('fee amount is: ', feeAmount) + const expectedMinusFee = expected.minus(feeAmount) const position = await dev.sTokensManager.positions(aliceFirstTokenId) const aliceLocked = toBigNumber(position.amount) @@ -1238,6 +1353,7 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { .then(toBigNumber) const afterBobBalance = await dev.dev.balanceOf(bob).then(toBigNumber) + console.log('after bob balance is: ', afterBobBalance.toNumber()) expect(afterAliceBalance.toNumber()).to.eq( beforeAliceBalance.plus(expectedMinusFee).toNumber() @@ -1247,6 +1363,7 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { ) }) }) + // TODO - ensure passing 0 gateway fee and 0 address don't charge anything }) }) }) diff --git a/test/lockup/lockup-s-token.ts b/test/lockup/lockup-s-token.ts index c367632d..e2f8d16e 100644 --- a/test/lockup/lockup-s-token.ts +++ b/test/lockup/lockup-s-token.ts @@ -38,7 +38,14 @@ contract('LockupTest', ([deployer, , user2, user3]) => { describe('success', () => { it('get nft token.', async () => { await dev.dev.approve(dev.lockup.address, 100) - await dev.lockup.depositToProperty(property.address, 100) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 100 + ) + const owner = await dev.sTokensManager.ownerOf(1) expect(owner).to.be.equal(deployer) const position = await dev.sTokensManager.positions(1) @@ -50,11 +57,25 @@ contract('LockupTest', ([deployer, , user2, user3]) => { }) it('get 2 nft token.', async () => { await dev.dev.approve(dev.lockup.address, 100) - await dev.lockup.depositToProperty(property.address, 100) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 100 + ) + const t1 = await getBlockTimestamp() await forwardBlockTimestamp(1) await dev.dev.approve(dev.lockup.address, 200) - await dev.lockup.depositToProperty(property.address, 200) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 200 + ) + const t2 = await getBlockTimestamp() const owner = await dev.sTokensManager.ownerOf(2) expect(owner).to.be.equal(deployer) @@ -73,7 +94,14 @@ contract('LockupTest', ([deployer, , user2, user3]) => { let info = await dev.lockup.getLockedupProperties() expect(info.length).to.be.equal(0) await dev.dev.approve(dev.lockup.address, 100) - await dev.lockup.depositToProperty(property.address, 100) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 100 + ) + info = await dev.lockup.getLockedupProperties() expect(info.length).to.be.equal(1) expect(info[0].property).to.be.equal(property.address) @@ -81,8 +109,20 @@ contract('LockupTest', ([deployer, , user2, user3]) => { }) it('get lockup info plus value.', async () => { await dev.dev.approve(dev.lockup.address, 300) - await dev.lockup.depositToProperty(property.address, 100) - await dev.lockup.depositToProperty(property.address, 200) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 100 + ) + + // @ts-expect-error overloading functions aren't working + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 200 + ) + const info = await dev.lockup.getLockedupProperties() expect(info.length).to.be.equal(1) expect(info[0].property).to.be.equal(property.address) @@ -100,8 +140,21 @@ contract('LockupTest', ([deployer, , user2, user3]) => { ).address ) await dev.dev.approve(dev.lockup.address, 300) - await dev.lockup.depositToProperty(property.address, 100) - await dev.lockup.depositToProperty(propertyAddress, 200) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 100 + ) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + propertyAddress, + 200 + ) + const info = await dev.lockup.getLockedupProperties() expect(info.length).to.be.equal(2) for (const lockupInfo of info) { @@ -114,7 +167,14 @@ contract('LockupTest', ([deployer, , user2, user3]) => { }) it('generate event.', async () => { await dev.dev.approve(dev.lockup.address, 100) - dev.lockup.depositToProperty(property.address, 100) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 100 + ) + const [_from, _property, _value, _tokenId] = await Promise.all([ getEventValue(dev.lockup)('Lockedup', '_from'), getEventValue(dev.lockup)('Lockedup', '_property'), @@ -128,7 +188,14 @@ contract('LockupTest', ([deployer, , user2, user3]) => { }) it('set storage value.', async () => { await dev.dev.approve(dev.lockup.address, 100) - await dev.lockup.depositToProperty(property.address, 100) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 100 + ) + const allValue = await dev.lockup.totalLocked() expect(allValue.toString()).to.be.equal('100') const propertyValue = await dev.lockup.totalLockedForProperty( @@ -144,7 +211,14 @@ contract('LockupTest', ([deployer, , user2, user3]) => { const beforePropertyBalance = await dev.dev.balanceOf(property.address) expect(beforeBalance.toString()).to.be.equal(deployerBalance.toString()) expect(beforePropertyBalance.toString()).to.be.equal('0') - await dev.lockup.depositToProperty(property.address, 100) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + 100 + ) + const afterBalance = await dev.dev.balanceOf(deployer).then(toBigNumber) const afterPropertyBalance = await dev.dev.balanceOf(property.address) expect(afterBalance.toString()).to.be.equal( @@ -160,21 +234,31 @@ contract('LockupTest', ([deployer, , user2, user3]) => { from: user2, }) ) - const res = await dev.lockup - .depositToProperty(propertyAddress, 100) - .catch(err) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + const res = await dev.lockup.methods[ + 'depositToProperty(address,uint256)' + ](propertyAddress, 100).catch(err) + validateErrorMessage(res, 'unable to stake to unauthenticated property') }) it('0 dev staking is not possible.', async () => { - const res = await dev.lockup - .depositToProperty(property.address, 0) - .catch(err) + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + const res = await dev.lockup.methods[ + 'depositToProperty(address,uint256)' + ](property.address, 0).catch(err) + validateErrorMessage(res, 'illegal deposit amount') }) it('user is not holding dev.', async () => { - const res = await dev.lockup - .depositToProperty(property.address, 100, { from: user3 }) - .catch(err) + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + const res = await dev.lockup.methods[ + 'depositToProperty(address,uint256)' + ](property.address, 100, { from: user3 }).catch(err) + validateErrorMessage(res, 'ERC20: transfer amount exceeds balance') }) }) @@ -286,7 +370,14 @@ contract('LockupTest', ([deployer, , user2, user3]) => { await dev.createMetrics(deployer, propertyAddress) ).address ) - await dev.lockup.depositToProperty(propertyAddress, 200) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + propertyAddress, + 200 + ) + const info = await dev.lockup.getLockedupProperties() expect(info.length).to.be.equal(2) for (const lockupInfo of info) { @@ -442,7 +533,14 @@ contract('LockupTest', ([deployer, , user2, user3]) => { await dev.createMetrics(deployer, propertyAddress) ).address ) - await dev.lockup.depositToProperty(propertyAddress, 200) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + propertyAddress, + 200 + ) + await dev.lockup.withdrawByPosition(tokenId, 100) const info = await dev.lockup.getLockedupProperties() expect(info.length).to.be.equal(1) diff --git a/test/lockup/lockup.ts b/test/lockup/lockup.ts index cb2a9786..9d555bc9 100644 --- a/test/lockup/lockup.ts +++ b/test/lockup/lockup.ts @@ -125,10 +125,14 @@ contract('LockupTest', ([deployer, user1, user2]) => { it('The reward is calculated and comes back to you.', async () => { await dev.dev.approve(dev.lockup.address, '10000000000000000000000') - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, '10000000000000000000000' ) + await dev.updateCap() const [reword, cap] = await calculate(dev, property) const result = await dev.lockup.calculateRewardAmount(property.address) From 9282d4e8b101740574248634b8bf965e402f6627 Mon Sep 17 00:00:00 2001 From: Stuart <11183054+stuartwk@users.noreply.github.com> Date: Tue, 21 Jun 2022 08:08:39 +0000 Subject: [PATCH 10/13] more depositToProperty overloading --- test/lockup/lockup-s-token-scenario.ts | 5 - test/market/market.ts | 12 +- test/s-token/s-token-manager.ts | 321 +++++++++++++++++++++---- test/withdraw/withdraw-scenario.ts | 64 ++++- test/withdraw/withdraw.ts | 33 ++- 5 files changed, 365 insertions(+), 70 deletions(-) diff --git a/test/lockup/lockup-s-token-scenario.ts b/test/lockup/lockup-s-token-scenario.ts index 706c9c05..885ba5d9 100644 --- a/test/lockup/lockup-s-token-scenario.ts +++ b/test/lockup/lockup-s-token-scenario.ts @@ -1324,8 +1324,6 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { .balanceOf(bob) .then(toBigNumber) - console.log('beforeBobBalance: ', beforeBobBalance.toNumber()) - const t1 = await getBlockTimestamp() const gatewayBasisFee = 300 // 3% const expected = toBigNumber(10) // In PolicyTestBase, the max staker reward per block is 10. @@ -1334,8 +1332,6 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { const feeAmount = (expected.toNumber() * gatewayBasisFee) / 10000 - console.log('fee amount is: ', feeAmount) - const expectedMinusFee = expected.minus(feeAmount) const position = await dev.sTokensManager.positions(aliceFirstTokenId) const aliceLocked = toBigNumber(position.amount) @@ -1353,7 +1349,6 @@ contract('LockupTest', ([deployer, user1, user2, user3]) => { .then(toBigNumber) const afterBobBalance = await dev.dev.balanceOf(bob).then(toBigNumber) - console.log('after bob balance is: ', afterBobBalance.toNumber()) expect(afterAliceBalance.toNumber()).to.eq( beforeAliceBalance.plus(expectedMinusFee).toNumber() diff --git a/test/market/market.ts b/test/market/market.ts index ee54661b..d99a9383 100755 --- a/test/market/market.ts +++ b/test/market/market.ts @@ -219,7 +219,11 @@ contract( }) }) it('Proxy to mapped Behavior Contract.', async () => { - await dev.lockup.depositToProperty(propertyAddress, 100000, { + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods[ + 'withdrawByPosition(uint256,uint256,address,uint256)' + ](propertyAddress, 100000, { from: propertyAuther, }) @@ -412,7 +416,11 @@ contract( }) }) it('Proxy to mapped Behavior Contract.', async () => { - await dev.lockup.depositToProperty(propertyAddress, 100000, { + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods[ + 'withdrawByPosition(uint256,uint256,address,uint256)' + ](propertyAddress, 100000, { from: propertyAuther, }) diff --git a/test/s-token/s-token-manager.ts b/test/s-token/s-token-manager.ts index 1653ab64..8b84fa5e 100644 --- a/test/s-token/s-token-manager.ts +++ b/test/s-token/s-token-manager.ts @@ -170,12 +170,24 @@ contract('STokensManager', ([deployer, user]) => { describe('tokenURI', () => { describe('success', () => { it('get token uri', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + const uri = await dev.sTokensManager.tokenURI(1) checkTokenUri(uri, property.address, 10000, 0) }) it('get custom token uri', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + await dev.sTokensManager.setTokenURIImage(1, 'ipfs://IPFS-CID', { from: user, }) @@ -183,7 +195,12 @@ contract('STokensManager', ([deployer, user]) => { checkTokenUri(uri, property.address, 10000, 0, 'ipfs://IPFS-CID') }) it('get descriptor token uri', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) await dev.sTokensManager.setTokenURIDescriptor( property.address, descriptor.address, @@ -205,7 +222,12 @@ contract('STokensManager', ([deployer, user]) => { describe('mint', () => { describe('success', () => { it('mint nft', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) const tokenId = await dev.sTokensManager.balanceOf(deployer) expect(tokenId.toString()).to.equal('1') const owner = await dev.sTokensManager.ownerOf(1) @@ -214,7 +236,12 @@ contract('STokensManager', ([deployer, user]) => { it('generate minted event', async () => { const [devLocal, propertyLocal] = await init() - devLocal.lockup.depositToProperty(propertyLocal.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + propertyLocal.address, + '10000' + ) const [_tokenId, _owner, _property, _amount, _price] = await Promise.all([ getEventValue(devLocal.sTokensManager)('Minted', 'tokenId'), @@ -230,7 +257,13 @@ contract('STokensManager', ([deployer, user]) => { expect(_price).to.equal('0') }) it('generate event', async () => { - dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + const [from, to, tokenId] = await Promise.all([ getEventValue(dev.sTokensManager)('Transfer', 'from'), getEventValue(dev.sTokensManager)('Transfer', 'to'), @@ -242,12 +275,24 @@ contract('STokensManager', ([deployer, user]) => { }) it('The counter will be incremented.', async () => { const [devLocal, propertyLocal] = await init() - devLocal.lockup.depositToProperty(propertyLocal.address, '10000') + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + propertyLocal.address, + '10000' + ) + const [_tokenId] = await Promise.all([ getEventValue(devLocal.sTokensManager)('Minted', 'tokenId'), ]) expect(_tokenId).to.equal('1') - devLocal.lockup.depositToProperty(propertyLocal.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + propertyLocal.address, + '10000' + ) const [_tokenId2] = await Promise.all([ getEventValue(devLocal.sTokensManager)('Minted', 'tokenId'), ]) @@ -266,7 +311,12 @@ contract('STokensManager', ([deployer, user]) => { describe('update', () => { describe('success', () => { it('update data', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) const t1 = await getBlockTimestamp() await forwardBlockTimestamp(2) const latestTokenId = 1 @@ -301,7 +351,12 @@ contract('STokensManager', ([deployer, user]) => { }) it('generate updated event data', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) const t1 = await getBlockTimestamp() await forwardBlockTimestamp(2) const latestTokenId = 1 @@ -347,7 +402,11 @@ contract('STokensManager', ([deployer, user]) => { describe('setTokenURIImage', () => { describe('success', () => { it('get data', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods[ + 'depositToProperty(uint256,uint256,address,uint256)' + ](property.address, '10000') await dev.sTokensManager.setTokenURIImage(1, 'ipfs://IPFS-CID', { from: user, }) @@ -355,7 +414,13 @@ contract('STokensManager', ([deployer, user]) => { checkTokenUri(tokenUri, property.address, 10000, 0, 'ipfs://IPFS-CID') }) it('get overwritten data', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + await dev.sTokensManager.setTokenURIImage(1, 'ipfs://IPFS-CID', { from: user, }) @@ -368,14 +433,24 @@ contract('STokensManager', ([deployer, user]) => { }) describe('fail', () => { it('not author.', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods[ + 'depositToProperty(uint256,uint256,address,uint256)' + ](property.address, '10000') + const res = await dev.sTokensManager .setTokenURIImage(1, '') .catch((err: Error) => err) validateErrorMessage(res, 'illegal access') }) it('was freezed', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods[ + 'depositToProperty(uint256,uint256,address,uint256)' + ](property.address, '10000') + await dev.sTokensManager.setTokenURIImage(1, 'http://dummy', { from: user, }) @@ -391,7 +466,12 @@ contract('STokensManager', ([deployer, user]) => { describe('freezeTokenURI', () => { describe('success', () => { it('data freezed', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods[ + 'depositToProperty(uint256,uint256,address,uint256)' + ](property.address, '10000') + await dev.sTokensManager.setTokenURIImage(1, 'http://dummy', { from: user, }) @@ -406,7 +486,12 @@ contract('STokensManager', ([deployer, user]) => { validateErrorMessage(res, 'freezed') }) it('generated event', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods[ + 'depositToProperty(uint256,uint256,address,uint256)' + ](property.address, '10000') + await dev.sTokensManager.setTokenURIImage(1, 'http://dummy', { from: user, }) @@ -421,7 +506,12 @@ contract('STokensManager', ([deployer, user]) => { }) describe('fail', () => { it('not author.', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods[ + 'depositToProperty(uint256,uint256,address,uint256)' + ](property.address, '10000') + await dev.sTokensManager.setTokenURIImage(1, 'http://dummy', { from: user, }) @@ -431,14 +521,24 @@ contract('STokensManager', ([deployer, user]) => { validateErrorMessage(res, 'illegal access') }) it('no uri data.', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) const res = await dev.sTokensManager .freezeTokenURI(1, { from: user }) .catch((err: Error) => err) validateErrorMessage(res, 'no data') }) it('already freezed.', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) await dev.sTokensManager.setTokenURIImage(1, 'http://dummy', { from: user, }) @@ -454,7 +554,12 @@ contract('STokensManager', ([deployer, user]) => { describe('position', () => { describe('success', () => { it('get data', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) const position = await dev.sTokensManager.positions(1) expect(position.property).to.equal(property.address) expect(toBigNumber(position.amount).toNumber()).to.equal(10000) @@ -476,7 +581,12 @@ contract('STokensManager', ([deployer, user]) => { describe('rewards', () => { describe('success', () => { it('get reward', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) const t1 = await getBlockTimestamp() await forwardBlockTimestamp(1) const position = await dev.sTokensManager.rewards(1) @@ -494,7 +604,12 @@ contract('STokensManager', ([deployer, user]) => { ) }) it('get updated reward', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) const t1 = await getBlockTimestamp() await forwardBlockTimestamp(1) const t2 = await getBlockTimestamp() @@ -530,7 +645,12 @@ contract('STokensManager', ([deployer, user]) => { describe('positionsOfProperty', () => { describe('success', () => { it('get token id', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) const tokenIds = await dev.sTokensManager.positionsOfProperty( property.address ) @@ -538,7 +658,13 @@ contract('STokensManager', ([deployer, user]) => { expect(tokenIds[0].toNumber()).to.equal(1) }) it('get token by property', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + const propertyAddress = getPropertyAddress( await dev.propertyFactory.create('test', 'TEST', user, { from: user, @@ -550,7 +676,13 @@ contract('STokensManager', ([deployer, user]) => { ).address ) - await dev.lockup.depositToProperty(propertyAddress, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + propertyAddress, + '10000' + ) + const tokenIds = await dev.sTokensManager.positionsOfProperty( property.address ) @@ -563,8 +695,18 @@ contract('STokensManager', ([deployer, user]) => { expect(tokenIds2[0].toNumber()).to.equal(2) }) it('get token list', async () => { - await dev.lockup.depositToProperty(property.address, '10000') - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + + // @ts-expect-error overloading functions aren't working + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) const tokenIds = await dev.sTokensManager.positionsOfProperty( property.address @@ -584,7 +726,13 @@ contract('STokensManager', ([deployer, user]) => { describe('positionsOfOwner', () => { describe('success', () => { it('get token id', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + const tokenIds = await dev.sTokensManager.positionsOfOwner(deployer) expect(tokenIds.length).to.equal(1) expect(tokenIds[0].toNumber()).to.equal(1) @@ -592,10 +740,23 @@ contract('STokensManager', ([deployer, user]) => { it('get token by owners', async () => { await dev.dev.mint(user, deployerBalance) await dev.dev.approve(dev.lockup.address, '100000', { from: user }) - await dev.lockup.depositToProperty(property.address, '10000') - await dev.lockup.depositToProperty(property.address, '10000', { - from: user, - }) + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + + // @ts-expect-error overloading functions aren't working + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000', + { + from: user, + } + ) + const tokenIds = await dev.sTokensManager.positionsOfOwner(deployer) expect(tokenIds.length).to.equal(1) expect(tokenIds[0].toNumber()).to.equal(1) @@ -604,8 +765,19 @@ contract('STokensManager', ([deployer, user]) => { expect(tokenIds2[0].toNumber()).to.equal(2) }) it('get token list', async () => { - await dev.lockup.depositToProperty(property.address, '10000') - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + + // @ts-expect-error overloading functions aren't working + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + const tokenIds = await dev.sTokensManager.positionsOfOwner(deployer) expect(tokenIds.length).to.equal(2) expect(tokenIds[0].toNumber()).to.equal(1) @@ -618,9 +790,24 @@ contract('STokensManager', ([deployer, user]) => { expect(tokenIds.length).to.equal(0) }) it('transfer token(index0)', async () => { - await dev.lockup.depositToProperty(property.address, '10000') - await dev.lockup.depositToProperty(property.address, '10000') - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + + // @ts-expect-error overloading functions aren't working + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + + // @ts-expect-error overloading functions aren't working + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) await dev.sTokensManager.transferFrom(deployer, user, 1) const tokenIds = await dev.sTokensManager.positionsOfOwner(deployer) expect(tokenIds.length).to.equal(2) @@ -633,9 +820,25 @@ contract('STokensManager', ([deployer, user]) => { expect(tokenIdsUser[0].toNumber()).to.equal(1) }) it('transfer token(index1)', async () => { - await dev.lockup.depositToProperty(property.address, '10000') - await dev.lockup.depositToProperty(property.address, '10000') - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + + // @ts-expect-error overloading functions aren't working + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + + // @ts-expect-error overloading functions aren't working + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + await dev.sTokensManager.transferFrom(deployer, user, 2) const tokenIds = await dev.sTokensManager.positionsOfOwner(deployer) expect(tokenIds.length).to.equal(2) @@ -648,9 +851,25 @@ contract('STokensManager', ([deployer, user]) => { expect(tokenIdsUser[0].toNumber()).to.equal(2) }) it('transfer token(index2)', async () => { - await dev.lockup.depositToProperty(property.address, '10000') - await dev.lockup.depositToProperty(property.address, '10000') - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + + // @ts-expect-error overloading functions aren't working + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + + // @ts-expect-error overloading functions aren't working + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + await dev.sTokensManager.transferFrom(deployer, user, 3) const tokenIds = await dev.sTokensManager.positionsOfOwner(deployer) expect(tokenIds.length).to.equal(2) @@ -694,7 +913,13 @@ contract('STokensManager', ([deployer, user]) => { expect(tmp.toString()).to.equal('0') }) it('get currentIndex token id number', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + const tmp = await dev.sTokensManager.currentIndex() expect(tmp.toString()).to.equal('1') }) @@ -734,7 +959,13 @@ contract('STokensManager', ([deployer, user]) => { ) }) it('set token uri image', async () => { - await dev.lockup.depositToProperty(property.address, '10000') + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) + await dev.sTokensManager.setTokenURIImage(1, 'ipfs://IPFS-CID', { from: user, }) diff --git a/test/withdraw/withdraw-scenario.ts b/test/withdraw/withdraw-scenario.ts index 82e3e104..62cf1978 100644 --- a/test/withdraw/withdraw-scenario.ts +++ b/test/withdraw/withdraw-scenario.ts @@ -29,7 +29,9 @@ contract('WithdrawTest', ([deployer, user1, user2, user3, user4]) => { await dev.dev.approve(dev.lockup.address, '10000000000000000000000', { from: alis, }) - await dev.lockup.depositToProperty( + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, '10000000000000000000000', { @@ -101,13 +103,17 @@ contract('WithdrawTest', ([deployer, user1, user2, user3, user4]) => { await dev.dev.approve(dev.lockup.address, '10000000000000000000000', { from: user3, }) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, '10000000000000000000000', { from: user3, } ) + timestamp = await getBlockTimestamp() }) @@ -230,13 +236,17 @@ contract('WithdrawTest', ([deployer, user1, user2, user3, user4]) => { await dev.dev.approve(dev.lockup.address, '10000000000000000000000', { from: user3, }) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, '10000000000000000000000', { from: user3, } ) + timestamps.set('a1', await getBlockTimestamp()) }) @@ -497,7 +507,10 @@ contract('WithdrawTest', ([deployer, user1, user2, user3, user4]) => { property2.address, 1 ) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property2.address, toBigNumber(10000).times(1e18), { from: bob } @@ -557,21 +570,29 @@ contract('WithdrawTest', ([deployer, user1, user2, user3, user4]) => { property.address, 1 ) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, toBigNumber(10000).times(1e18), { from: bob, } ) + await forwardBlockTimestamp(1) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, toBigNumber(10000).times(1e18), { from: bob, } ) + await forwardBlockTimestamp(1) await dev.metricsFactory.__setMetricsCountPerProperty( property.address, @@ -604,7 +625,10 @@ contract('WithdrawTest', ([deployer, user1, user2, user3, user4]) => { { from: carol } ) await dev.dev.mint(carol, aliceBalance) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, toBigNumber(10000).times(1e18), { from: carol } @@ -744,15 +768,22 @@ contract('WithdrawTest', ([deployer, user1, user2, user3, user4]) => { await dev.dev.approve(dev.lockup.address, '20000000000000000000000', { from: carol, }) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, '10000000000000000000000', { from: bob, } ) + timestamp = await getBlockTimestamp() - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, toBigNumber('10000000000000000000000').times('0.25'), { @@ -947,13 +978,16 @@ contract('WithdrawTest', ([deployer, user1, user2, user3, user4]) => { await dev.dev.approve(dev.lockup.address, '50000000000000000000000', { from: dave, }) - await dev.lockup.depositToProperty( + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property1.address, '10000000000000000000000', { from: dave, } ) + await forwardBlockTimestamp(3) }) @@ -1000,13 +1034,16 @@ contract('WithdrawTest', ([deployer, user1, user2, user3, user4]) => { ) }) it(`Alice does staking 2500 to Property2, Property2 is 20% of the total rewards`, async () => { - await dev.lockup.depositToProperty( + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property2.address, '2500000000000000000000', { from: dave, } ) + const total = await dev.lockup.totalLocked().then(toBigNumber) const p1 = await dev.lockup .totalLockedForProperty(property1.address) @@ -1022,13 +1059,16 @@ contract('WithdrawTest', ([deployer, user1, user2, user3, user4]) => { }% of the total rewards, Property2 is ${ 250000 / 16250 }% of the total rewards`, async () => { - await dev.lockup.depositToProperty( + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property3.address, '3750000000000000000000', { from: dave, } ) + const total = await dev.lockup.totalLocked().then(toBigNumber) const p1 = await dev.lockup .totalLockedForProperty(property1.address) diff --git a/test/withdraw/withdraw.ts b/test/withdraw/withdraw.ts index 011b6941..ce59aa70 100644 --- a/test/withdraw/withdraw.ts +++ b/test/withdraw/withdraw.ts @@ -60,13 +60,17 @@ contract('WithdrawTest', ([deployer, user1, , user3]) => { await dev.dev.approve(dev.lockup.address, '10000000000000000000000', { from: alis, }) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, '10000000000000000000000', { from: alis, } ) + await forwardBlockTimestamp(1) const prev = await dev.dev.totalSupply().then(toBigNumber) const balance = await dev.dev.balanceOf(deployer).then(toBigNumber) @@ -88,13 +92,17 @@ contract('WithdrawTest', ([deployer, user1, , user3]) => { await dev.dev.approve(dev.lockup.address, '10000000000000000000000', { from: user3, }) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, '10000000000000000000000', { from: user3, } ) + const t1 = await getBlockTimestamp() await forwardBlockTimestamp(1) const totalSupply = await property.totalSupply().then(toBigNumber) @@ -142,13 +150,17 @@ contract('WithdrawTest', ([deployer, user1, , user3]) => { await dev.dev.approve(dev.lockup.address, '10000000000000000000000', { from: user3, }) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property.address, '10000000000000000000000', { from: user3, } ) + const t1 = await getBlockTimestamp() await forwardBlockTimestamp(1) @@ -299,21 +311,30 @@ contract('WithdrawTest', ([deployer, user1, , user3]) => { it(`cap`, async () => { const [dev, [property1, property2, property3]] = await prepare() - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property1.address, toBigNumber(1000000000), { from: alis, } ) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property2.address, toBigNumber(2000000000), { from: alis, } ) - await dev.lockup.depositToProperty( + + // @ts-expect-error overloading functions aren't working + // pulled from https://github.com/trufflesuite/truffle/issues/3506 + await dev.lockup.methods['depositToProperty(address,uint256)']( property3.address, toBigNumber(3000000000), { From 815d50f478aefe3bb9a8f27ff359d501e1a32f97 Mon Sep 17 00:00:00 2001 From: Stuart <11183054+stuartwk@users.noreply.github.com> Date: Tue, 21 Jun 2022 08:44:12 +0000 Subject: [PATCH 11/13] updates incorrect depositToProperty params --- test/market/market.ts | 24 ++++++++++++++---------- test/s-token/s-token-manager.ts | 14 ++++++++------ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/test/market/market.ts b/test/market/market.ts index d99a9383..e3bd02c6 100755 --- a/test/market/market.ts +++ b/test/market/market.ts @@ -221,11 +221,13 @@ contract( it('Proxy to mapped Behavior Contract.', async () => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods[ - 'withdrawByPosition(uint256,uint256,address,uint256)' - ](propertyAddress, 100000, { - from: propertyAuther, - }) + await dev.lockup.methods['depositToProperty(uint256,uint256)']( + propertyAddress, + 100000, + { + from: propertyAuther, + } + ) const marketInstance = await marketContract.at(marketAddress1) marketInstance @@ -418,11 +420,13 @@ contract( it('Proxy to mapped Behavior Contract.', async () => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods[ - 'withdrawByPosition(uint256,uint256,address,uint256)' - ](propertyAddress, 100000, { - from: propertyAuther, - }) + await dev.lockup.methods['depositToProperty(address,uint256)']( + propertyAddress, + 100000, + { + from: propertyAuther, + } + ) const marketInstance = await marketContract.at(marketAddress1) void marketInstance.authenticateFromPropertyFactory( diff --git a/test/s-token/s-token-manager.ts b/test/s-token/s-token-manager.ts index 8b84fa5e..b41260a3 100644 --- a/test/s-token/s-token-manager.ts +++ b/test/s-token/s-token-manager.ts @@ -404,9 +404,10 @@ contract('STokensManager', ([deployer, user]) => { it('get data', async () => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods[ - 'depositToProperty(uint256,uint256,address,uint256)' - ](property.address, '10000') + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) await dev.sTokensManager.setTokenURIImage(1, 'ipfs://IPFS-CID', { from: user, }) @@ -435,9 +436,10 @@ contract('STokensManager', ([deployer, user]) => { it('not author.', async () => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods[ - 'depositToProperty(uint256,uint256,address,uint256)' - ](property.address, '10000') + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) const res = await dev.sTokensManager .setTokenURIImage(1, '') From 3f9aaf2751bb9d66f50d8b151746d3a7033e6ef0 Mon Sep 17 00:00:00 2001 From: Stuart <11183054+stuartwk@users.noreply.github.com> Date: Tue, 21 Jun 2022 09:01:34 +0000 Subject: [PATCH 12/13] fixes depositToProperty params --- test/market/market.ts | 2 +- test/s-token/s-token-manager.ts | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/test/market/market.ts b/test/market/market.ts index e3bd02c6..af9c290e 100755 --- a/test/market/market.ts +++ b/test/market/market.ts @@ -221,7 +221,7 @@ contract( it('Proxy to mapped Behavior Contract.', async () => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods['depositToProperty(uint256,uint256)']( + await dev.lockup.methods['depositToProperty(address,uint256)']( propertyAddress, 100000, { diff --git a/test/s-token/s-token-manager.ts b/test/s-token/s-token-manager.ts index b41260a3..6c9a2fb1 100644 --- a/test/s-token/s-token-manager.ts +++ b/test/s-token/s-token-manager.ts @@ -449,9 +449,10 @@ contract('STokensManager', ([deployer, user]) => { it('was freezed', async () => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods[ - 'depositToProperty(uint256,uint256,address,uint256)' - ](property.address, '10000') + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) await dev.sTokensManager.setTokenURIImage(1, 'http://dummy', { from: user, @@ -470,9 +471,10 @@ contract('STokensManager', ([deployer, user]) => { it('data freezed', async () => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods[ - 'depositToProperty(uint256,uint256,address,uint256)' - ](property.address, '10000') + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) await dev.sTokensManager.setTokenURIImage(1, 'http://dummy', { from: user, @@ -490,9 +492,10 @@ contract('STokensManager', ([deployer, user]) => { it('generated event', async () => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods[ - 'depositToProperty(uint256,uint256,address,uint256)' - ](property.address, '10000') + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) await dev.sTokensManager.setTokenURIImage(1, 'http://dummy', { from: user, @@ -510,9 +513,10 @@ contract('STokensManager', ([deployer, user]) => { it('not author.', async () => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods[ - 'depositToProperty(uint256,uint256,address,uint256)' - ](property.address, '10000') + await dev.lockup.methods['depositToProperty(address,uint256)']( + property.address, + '10000' + ) await dev.sTokensManager.setTokenURIImage(1, 'http://dummy', { from: user, From 972169c361f90b19f5321aa694e32608586dd02e Mon Sep 17 00:00:00 2001 From: Stuart <11183054+stuartwk@users.noreply.github.com> Date: Tue, 21 Jun 2022 09:32:08 +0000 Subject: [PATCH 13/13] passing s-token tests --- test/s-token/s-token-manager.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/s-token/s-token-manager.ts b/test/s-token/s-token-manager.ts index 6c9a2fb1..6ca88958 100644 --- a/test/s-token/s-token-manager.ts +++ b/test/s-token/s-token-manager.ts @@ -238,7 +238,7 @@ contract('STokensManager', ([deployer, user]) => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods['depositToProperty(address,uint256)']( + devLocal.lockup.methods['depositToProperty(address,uint256)']( propertyLocal.address, '10000' ) @@ -259,7 +259,7 @@ contract('STokensManager', ([deployer, user]) => { it('generate event', async () => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods['depositToProperty(address,uint256)']( + dev.lockup.methods['depositToProperty(address,uint256)']( property.address, '10000' ) @@ -278,7 +278,7 @@ contract('STokensManager', ([deployer, user]) => { // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods['depositToProperty(address,uint256)']( + devLocal.lockup.methods['depositToProperty(address,uint256)']( propertyLocal.address, '10000' ) @@ -289,7 +289,7 @@ contract('STokensManager', ([deployer, user]) => { expect(_tokenId).to.equal('1') // @ts-expect-error overloading functions aren't working // pulled from https://github.com/trufflesuite/truffle/issues/3506 - await dev.lockup.methods['depositToProperty(address,uint256)']( + devLocal.lockup.methods['depositToProperty(address,uint256)']( propertyLocal.address, '10000' )