Skip to content

Commit

Permalink
getMintPriceForDrop
Browse files Browse the repository at this point in the history
julesGoullee committed Nov 7, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 854292f commit 3024954
Showing 8 changed files with 363 additions and 36 deletions.
8 changes: 4 additions & 4 deletions packages/contracts/contracts/CyberDropBase.sol
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ contract CyberDropBase is CyberDestinationFactoryBase {
require(drop.minted < drop.amountCap, 'CR');
}

uint256 price = getMintPrice(drop);
uint256 price = getMintPriceForDrop(drop);
require(msg.value >= price, 'IA');

_safeMint(sender, _tokenId, 1, '');
@@ -126,10 +126,10 @@ contract CyberDropBase is CyberDestinationFactoryBase {
if (drop.amountCap != 0) {
require(drop.minted < drop.amountCap, 'CR');
}
return getMintPrice(drop);
return getMintPriceForDrop(drop);
}

function getMintPrice(LibDropStorage.Drop memory drop)
function getMintPriceForDrop(LibDropStorage.Drop memory drop)
public
view
returns (uint256)
@@ -153,7 +153,7 @@ contract CyberDropBase is CyberDestinationFactoryBase {
uint256 _priceEnd,
uint256 _stepDuration
) public pure returns (uint256) {
// https://www.desmos.com/calculator/ipv4mm7hrh
// https://www.desmos.com/calculator/oajpdvew5q
// f\left(x\right)=\frac{s\ \cdot d\ +\ \operatorname{mod}\left(x,\ g\right)\ \cdot\ \left(s\ -\ l\right)\ -\ x\ \cdot\ \left(s\ -\ l\right)\ \ }{d}
// (s * d + (x % g) * (s - l) - x * (s - l) / d
return
322 changes: 320 additions & 2 deletions packages/contracts/test/CyberDestinationFactories.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ const memory: any = {}

const tokenURI = (uri: string) => `ipfs://${uri}`

describe.only('CyberDestinationFactories', function () {
describe('CyberDestinationFactories', function () {
before(async () => {
memory.signers = await ethers.getSigners()
})
@@ -808,6 +808,324 @@ describe.only('CyberDestinationFactories', function () {
})
})

describe('getMintPriceForDrop', () => {
it('Should get mint price for drop', async () => {
const now = Date.now()
await ethers.provider.send('evm_setNextBlockTimestamp', [now])
await ethers.provider.send('evm_mine', [])
expect(
await memory.contract.getMintPriceForDrop({
timeStart: now,
timeEnd: now + 1800,
priceStart: 50,
priceEnd: 5,
stepDuration: 300,
amountCap: 1,
shareCyber: 50,
creator: memory.other.address,
minted: 0,
})
).to.be.eq('50')
await ethers.provider.send('evm_increaseTime', [600])
await ethers.provider.send('evm_mine', [])
expect(
await memory.contract.getMintPriceForDrop({
timeStart: now,
timeEnd: now + 1800,
priceStart: 50,
priceEnd: 5,
stepDuration: 300,
amountCap: 1,
shareCyber: 50,
creator: memory.other.address,
minted: 0,
})
).to.be.eq('35')
await ethers.provider.send('evm_increaseTime', [1200])
await ethers.provider.send('evm_mine', [])
expect(
await memory.contract.getMintPriceForDrop({
timeStart: now,
timeEnd: now + 1800,
priceStart: 50,
priceEnd: 5,
stepDuration: 300,
amountCap: 1,
shareCyber: 50,
creator: memory.other.address,
minted: 0,
})
).to.be.eq('5')
})
})

describe('GetMintPriceForToken', () => {
it('Should get mint price for token', async () => {
const uri = 'Qmsfzefi221ifjzifj'
const timeStart = parseInt((Date.now() / 1000 - 100).toString())
const timeEnd = parseInt((Date.now() / 1000 + 100).toString())
const priceStart = 100
const priceEnd = 10
const stepDuration = 20
const amountCap = 10
const shareCyber = 50
const nonce = 0
const signature = await signCreateDropRequest(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
memory.other.address,
nonce,
memory.manager
)
await memory.contract
.connect(memory.other)
.createDrop(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
signature
)
const tokenId = 0
const mintPrice = await memory.contract.getMintPriceForToken(tokenId)
expect(mintPrice).to.be.eq('55')
})

it('Should get mint price for token throw out of time before', async () => {
const uri = 'Qmsfzefi221ifjzifj'
const timeStart = parseInt((Date.now() / 1000 + 100).toString())
const timeEnd = parseInt((Date.now() / 1000 + 500).toString())
const priceStart = 100
const priceEnd = 10
const stepDuration = 20
const amountCap = 10
const shareCyber = 50
const nonce = 0
const signature = await signCreateDropRequest(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
memory.other.address,
nonce,
memory.manager
)
await memory.contract
.connect(memory.other)
.createDrop(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
signature
)
const tokenId = 0
await expect(
memory.contract.getMintPriceForToken(tokenId)
).to.be.revertedWith('OOT')
})

it('Should get mint price for token throw out of time after', async () => {
const uri = 'Qmsfzefi221ifjzifj'
const timeStart = parseInt((Date.now() / 1000 - 500).toString())
const timeEnd = parseInt((Date.now() / 1000 - 100).toString())
const priceStart = 100
const priceEnd = 10
const stepDuration = 20
const amountCap = 10
const shareCyber = 50
const nonce = 0
const signature = await signCreateDropRequest(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
memory.other.address,
nonce,
memory.manager
)
await memory.contract
.connect(memory.other)
.createDrop(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
signature
)
const tokenId = 0
await expect(
memory.contract.getMintPriceForToken(tokenId)
).to.be.revertedWith('OOT')
})

it('Should get mint price for token without cap', async () => {
const uri = 'Qmsfzefi221ifjzifj'
const timeStart = parseInt((Date.now() / 1000 - 100).toString())
const timeEnd = parseInt((Date.now() / 1000 + 100).toString())
const priceStart = 100
const priceEnd = 10
const stepDuration = 20
const amountCap = 0
const shareCyber = 50
const nonce = 0
const signature = await signCreateDropRequest(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
memory.other.address,
nonce,
memory.manager
)
await memory.contract
.connect(memory.other)
.createDrop(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
signature
)
const tokenId = 0
const mintPrice = await memory.contract.getMintPriceForToken(tokenId)
expect(mintPrice).to.be.eq('55')
})

it('Should get mint price for token throw when cap reach', async () => {
const uri = 'Qmsfzefi221ifjzifj'
const timeStart = parseInt((Date.now() / 1000 - 100).toString())
const timeEnd = parseInt((Date.now() / 1000 + 100).toString())
const priceStart = 100
const priceEnd = 10
const stepDuration = 20
const amountCap = 1
const shareCyber = 50
const nonce = 0
const signature = await signCreateDropRequest(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
memory.other.address,
nonce,
memory.manager
)
await memory.contract
.connect(memory.other)
.createDrop(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
signature
)
const tokenId = 0
const mintPrice = await memory.contract.getMintPriceForToken(tokenId)
expect(mintPrice).to.be.eq('55')
await memory.contract.connect(memory.other2).mint(tokenId, {
value: mintPrice,
})
await expect(
memory.contract.getMintPriceForToken(tokenId)
).to.be.revertedWith('CR')
})

it('Should get mint price for with time spent', async () => {
const now = Date.now()
const uri = 'Qmsfzefi221ifjzifj'
const timeStart = parseInt((now / 1000).toString())
const timeEnd = parseInt((now / 1000 + 1800).toString())
const priceStart = 50
const priceEnd = 5
const stepDuration = 300
const amountCap = 10
const shareCyber = 50
const nonce = 0
const signature = await signCreateDropRequest(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
memory.other.address,
nonce,
memory.manager
)
await memory.contract
.connect(memory.other)
.createDrop(
uri,
timeStart,
timeEnd,
priceStart,
priceEnd,
stepDuration,
amountCap,
shareCyber,
signature
)
const tokenId = 0
await ethers.provider.send('evm_increaseTime', [100])
await ethers.provider.send('evm_mine', [])
expect(await memory.contract.getMintPriceForToken(tokenId)).to.be.eq('50')
await ethers.provider.send('evm_increaseTime', [300])
await ethers.provider.send('evm_mine', [])
expect(await memory.contract.getMintPriceForToken(tokenId)).to.be.eq('42')
await ethers.provider.send('evm_increaseTime', [600])
await ethers.provider.send('evm_mine', [])
expect(await memory.contract.getMintPriceForToken(tokenId)).to.be.eq('27')
await ethers.provider.send('evm_increaseTime', [700])
await ethers.provider.send('evm_mine', [])
expect(await memory.contract.getMintPriceForToken(tokenId)).to.be.eq('12')
})
})

describe('Mint', () => {
it('Should mint ', async () => {
const uri = 'Qmsfzefi221ifjzifj'
@@ -1198,7 +1516,7 @@ describe.only('CyberDestinationFactories', function () {
expect(drop.minted).to.eq('2')
})

it('MintEdition throw cap reach', async () => {
it('Should mint throw cap reach', async () => {
const uri = 'Qmsfzefi221ifjzifj'
const timeStart = parseInt((Date.now() / 1000 - 100).toString())
const timeEnd = parseInt((Date.now() / 1000 + 10).toString())
Loading

0 comments on commit 3024954

Please sign in to comment.