Skip to content

Commit

Permalink
Merge pull request #16 from The-Poolz/issue-373
Browse files Browse the repository at this point in the history
Issue 373
  • Loading branch information
YouStillAlive authored Dec 28, 2023
2 parents a04f5e2 + f24a789 commit 89aba3f
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ jobs:
- name: compile contracts
run: npx hardhat compile

- name: deploy simulation
run: npx hardhat run ./scripts/deploy.ts
- name: deployment and testing
run: npx hardhat test
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ npm i
## Truffle dashboard deployment

```console
truffle dashboard
npx hardhat run ./scripts/fileImport.ts
```

```console
npx hardhat run ./scripts/fileImport.ts
truffle dashboard
```

```console
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "solidity-coverage"
const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
solidity: {
version: "0.8.21",
version: "0.8.19",
settings: {
evmVersion: "byzantium",
optimizer: {
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "integrate-v3",
"version": "0.0.1",
"description": "Contract for creating fixed price lunch",
"description": "Deploying and testing Poolz contracts",
"main": "index.js",
"scripts": {
"test": "npx hardhat test",
"postinstall": "npx hardhat run ./scripts/fileImport.ts",
"menu": "npx hardhat compile && .\\scripts\\separate-scripts.bat",
"testnet": "npx hardhat compile && npx ts-node ./scripts/testnet.ts"
},
Expand All @@ -16,8 +17,6 @@
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-etherscan": "^3.1.2",
"@openzeppelin/contracts": "^4.8.3",
"@poolzfinance/poolz-helper-v2": "^2.2.1",
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
"@truffle/dashboard-hardhat-plugin": "0.2.7",
"@typechain/ethers-v5": "^10.1.1",
Expand All @@ -43,6 +42,8 @@
"ts-generator": "^0.1.1",
"ts-node": "^10.9.1",
"typechain": "^8.1.1",
"@openzeppelin/contracts": "^4.8.3",
"@poolzfinance/poolz-helper-v2": "^2.2.2",
"typescript": "^4.9.3"
},
"dependencies": {
Expand Down
8 changes: 4 additions & 4 deletions scripts/utility/builders.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Wallet } from "ethers"
import { gasLimit, gasPrice, amount } from "./constants"
import { SimpleBuilder, SimpleRefundBuilder, ERC20Token, VaultManager } from "../../typechain-types"
import { getSignature } from "./creation"
import { BuilderState } from "../../typechain-types"
import { BuilderState } from "../../typechain-types/contracts/LockDealNFT/contracts/Builders/SimpleBuilder/SimpleBuilder"
import { gasLimit, gasPrice, amount } from "./constants"
import { finishTime } from "./constants"
import { getSignature } from "./creation"
import { Wallet } from "ethers"

const sendData: BuilderState.BuilderStruct = {
userPools: [
Expand Down
154 changes: 154 additions & 0 deletions test/TokenVaultId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import { getSignature } from "../scripts/utility/creation"
import { BuilderState } from "../typechain-types/contracts/LockDealNFT/contracts/Builders/SimpleRefundBuilder/SimpleRefundBuilder"
import {
VaultManager,
LockDealNFT,
DealProvider,
LockDealProvider,
TimedDealProvider,
RefundProvider,
SimpleRefundBuilder,
CollateralProvider,
ERC20Token,
} from "../typechain-types"
import { time } from "@nomicfoundation/hardhat-network-helpers"
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"
import { deploy } from "../scripts/utility/deployment"
import { BigNumber, Wallet } from "ethers"
import { ethers } from "hardhat"
import { expect } from "chai"

describe("Token Vault Id", function () {
let vaultManager: VaultManager
let lockDealNFT: LockDealNFT
let dealProvider: DealProvider
let lockProvider: LockDealProvider
let timedProvider: TimedDealProvider
let collateralProvider: CollateralProvider
let refundProvider: RefundProvider
let simpleRefundBuilder: SimpleRefundBuilder
let token: ERC20Token
let mainCoin: ERC20Token
let tempToken: ERC20Token
let tempToken2: ERC20Token
const tokenVaultId = 2
const mainCoinVaultId = 3
let poolId: BigNumber
let startTime: number
let finishTime: number
let params: [BigNumber, number, number, BigNumber, number]
let receiver: SignerWithAddress
let addresses: string[]
const ONE_DAY = 86400
const amount = ethers.utils.parseUnits("1", 18)
let user: Wallet

before(async () => {
;[receiver] = await ethers.getSigners()
user = receiver as unknown as Wallet
vaultManager = (await deploy("VaultManager")) as VaultManager
lockDealNFT = (await deploy("LockDealNFT", vaultManager.address, "")) as LockDealNFT
dealProvider = (await deploy("DealProvider", lockDealNFT.address)) as DealProvider
lockProvider = (await deploy("LockDealProvider", lockDealNFT.address, dealProvider.address)) as LockDealProvider
timedProvider = (await deploy(
"TimedDealProvider",
lockDealNFT.address,
lockProvider.address
)) as TimedDealProvider
collateralProvider = (await deploy(
"CollateralProvider",
lockDealNFT.address,
dealProvider.address
)) as CollateralProvider
refundProvider = (await deploy(
"RefundProvider",
lockDealNFT.address,
collateralProvider.address
)) as RefundProvider
token = (await deploy("ERC20Token", "Token", "TOKEN")) as ERC20Token
mainCoin = (await deploy("ERC20Token", "MainCoin", "USDT")) as ERC20Token
tempToken = (await deploy("ERC20Token", "Token1", "TOKEN1")) as ERC20Token
tempToken2 = (await deploy("ERC20Token", "Token2", "TOKEN2")) as ERC20Token
simpleRefundBuilder = (await deploy(
"SimpleRefundBuilder",
lockDealNFT.address,
refundProvider.address,
collateralProvider.address
)) as SimpleRefundBuilder
await vaultManager.setTrustee(lockDealNFT.address)

await lockDealNFT.setApprovedContract(dealProvider.address, true)
await lockDealNFT.setApprovedContract(lockProvider.address, true)
await lockDealNFT.setApprovedContract(timedProvider.address, true)
await lockDealNFT.setApprovedContract(collateralProvider.address, true)
await lockDealNFT.setApprovedContract(refundProvider.address, true)
await lockDealNFT.setApprovedContract(simpleRefundBuilder.address, true)
await token.approve(vaultManager.address, amount.mul(100))
await mainCoin.approve(vaultManager.address, amount.mul(100))
await lockDealNFT.approvePoolTransfers(true)
console.log("\n")
})

beforeEach(async () => {
poolId = await lockDealNFT.totalSupply()
startTime = (await time.latest()) + ONE_DAY // plus 1 day
finishTime = startTime + 7 * ONE_DAY // plus 7 days from `startTime`
const mainCoinAmount = amount.div(2)
addresses = [receiver.address, token.address, mainCoin.address, timedProvider.address]
params = [amount, startTime, finishTime, mainCoinAmount, finishTime]
})

it("should create 4 vaults", async () => {
await vaultManager["createNewVault(address)"](tempToken.address)
await vaultManager["createNewVault(address)"](tempToken2.address)
await vaultManager["createNewVault(address)"](token.address)
await vaultManager["createNewVault(address)"](mainCoin.address)
expect(await vaultManager.vaultIdToTokenAddress(0)).to.equal(tempToken.address)
expect(await vaultManager.vaultIdToTokenAddress(1)).to.equal(tempToken2.address)
expect(await vaultManager.vaultIdToTokenAddress(tokenVaultId)).to.equal(token.address)
expect(await vaultManager.vaultIdToTokenAddress(mainCoinVaultId)).to.equal(mainCoin.address)
})

it("checking vaultIds by creating RefundProvider NFT", async () => {
const tokenSignature = await getSignature(user, vaultManager, token, token.address, amount)
const mainCoinsignature = await getSignature(user, vaultManager, token, mainCoin.address, amount.div(2))
await refundProvider.connect(user).createNewRefundPool(addresses, params, tokenSignature, mainCoinsignature)
expect(await lockDealNFT.poolIdToVaultId(poolId)).to.equal(tokenVaultId)
expect(await lockDealNFT.poolIdToVaultId(poolId.add(1))).to.equal(tokenVaultId)
expect(await lockDealNFT.poolIdToVaultId(poolId.add(2))).to.equal(mainCoinVaultId)
expect(await lockDealNFT.poolIdToVaultId(poolId.add(3))).to.equal(mainCoinVaultId)
expect(await lockDealNFT.poolIdToVaultId(poolId.add(4))).to.equal(tokenVaultId)
expect(await lockDealNFT.poolIdToVaultId(poolId.add(5))).to.equal(mainCoinVaultId)
})

it("checking vaultIds by creating simple refund builder NFTs", async () => {
const addresses = [timedProvider.address, token.address, mainCoin.address]
const userData = _createUsers(amount.toString(), `2`)
const params: string[][] = [
[amount.toString(), finishTime.toString()],
[startTime.toString(), finishTime.toString()],
]
const tokenSignature = await getSignature(user, vaultManager, token, token.address, amount.mul(2))
const mainCoinsignature = await getSignature(user, vaultManager, token, mainCoin.address, amount)
await simpleRefundBuilder
.connect(user)
.buildMassPools(addresses, userData, params, tokenSignature, mainCoinsignature)
expect(await lockDealNFT.poolIdToVaultId(poolId)).to.equal(tokenVaultId)
expect(await lockDealNFT.poolIdToVaultId(poolId.add(1))).to.equal(tokenVaultId)
expect(await lockDealNFT.poolIdToVaultId(poolId.add(2))).to.equal(mainCoinVaultId)
expect(await lockDealNFT.poolIdToVaultId(poolId.add(3))).to.equal(mainCoinVaultId)
expect(await lockDealNFT.poolIdToVaultId(poolId.add(4))).to.equal(tokenVaultId)
expect(await lockDealNFT.poolIdToVaultId(poolId.add(5))).to.equal(mainCoinVaultId)
})

function _createUsers(amount: string, userCount: string): BuilderState.BuilderStruct {
const pools = []
const length = parseInt(userCount)
// Create signers
for (let i = 0; i < length; ++i) {
pools.push({ user: user.address, amount: amount })
}
const totalAmount = ethers.BigNumber.from(amount).mul(length)
return { userPools: pools, totalAmount: totalAmount }
}
})

0 comments on commit 89aba3f

Please sign in to comment.