Skip to content

Commit

Permalink
Scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Apr 30, 2024
1 parent ed40718 commit cbdc763
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
9 changes: 4 additions & 5 deletions scripts/nft-rental-marketplace/02-create-rental-offer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ZeroAddress } from 'ethers'
import { print, colors } from '../../utils/misc'
import { callContractFunction } from '../../utils/write-contract'
import { randomBytes } from 'crypto'
import { etherPerDayToWeiPerSecond } from '../../utils/bignumber'
import { EMPTY_BYTES, ONE_DAY } from '../../utils/constants'
import { USER_ROLE } from '../../utils/roles'
import { USER_ROLE_MOONBEAM } from '../../utils/roles'
import { ethers } from 'hardhat'
import { RentalOffer } from '../../utils/types'

Expand All @@ -16,14 +15,14 @@ async function main() {
const RENTAL_OFFER: RentalOffer = {
nonce: `0x${randomBytes(32).toString('hex')}`,
lender: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906',
borrower: ZeroAddress,
borrower: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906',
tokenId: 1994,
tokenAddress: '0xcb13945ca8104f813992e4315f8ffefe64ac49ca', // GLMR jungle address
feeTokenAddress: '0xd10078fdbc835726c79533a4a19db40cfad69d7f', // GLMB address
feeAmountPerSecond: etherPerDayToWeiPerSecond('0.01'),
feeAmountPerSecond: etherPerDayToWeiPerSecond('0'),
deadline: blockTimestamp + ONE_DAY,
minDuration: 0,
roles: [USER_ROLE],
roles: [USER_ROLE_MOONBEAM],
rolesData: [EMPTY_BYTES],
}
await callContractFunction(CONTRACT_NAME, CONTRACT_FUNCTION, [RENTAL_OFFER])
Expand Down
36 changes: 36 additions & 0 deletions scripts/nft-rental-marketplace/03-accept-rental-offer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { print, colors } from '../../utils/misc'
import { callContractFunction } from '../../utils/write-contract'
import { etherPerDayToWeiPerSecond } from '../../utils/bignumber'
import { EMPTY_BYTES, ONE_DAY } from '../../utils/constants'
import { USER_ROLE_MOONBEAM } from '../../utils/roles'
import { RentalOffer } from '../../utils/types'

const CONTRACT_NAME = 'NftRentalMarketplace'
const CONTRACT_FUNCTION = 'acceptRentalOffer'

async function main() {
const RENTAL_OFFER: RentalOffer = {
nonce: '115457453593754985652281111685552019968813348573560119211069111442109350087626',
lender: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906',
borrower: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906',
tokenId: 1994,
tokenAddress: '0xcb13945ca8104f813992e4315f8ffefe64ac49ca', // GLMR jungle address
feeTokenAddress: '0xd10078fdbc835726c79533a4a19db40cfad69d7f', // GLMB address
feeAmountPerSecond: etherPerDayToWeiPerSecond('0'),
deadline: 1714599894,
minDuration: 0,
roles: [USER_ROLE_MOONBEAM],
rolesData: [EMPTY_BYTES],
}
const DURATION = ONE_DAY / 2
await callContractFunction(CONTRACT_NAME, CONTRACT_FUNCTION, [RENTAL_OFFER, DURATION])
}

main()
.then(() => {
print(colors.bigSuccess, 'All done!')
})
.catch(error => {
console.error(error)
process.exitCode = 1
})
35 changes: 35 additions & 0 deletions scripts/nft-rental-marketplace/04-cancel-rental-offer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { print, colors } from '../../utils/misc'
import { callContractFunction } from '../../utils/write-contract'
import { etherPerDayToWeiPerSecond } from '../../utils/bignumber'
import { EMPTY_BYTES } from '../../utils/constants'
import { USER_ROLE_MOONBEAM } from '../../utils/roles'
import { RentalOffer } from '../../utils/types'

const CONTRACT_NAME = 'NftRentalMarketplace'
const CONTRACT_FUNCTION = 'cancelRentalOffer'

async function main() {
const RENTAL_OFFER: RentalOffer = {
nonce: '41073076454465649804684789998370311225937584494094599799884085085462612297440',
lender: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906',
borrower: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906',
tokenId: 1994,
tokenAddress: '0xcb13945ca8104f813992e4315f8ffefe64ac49ca', // GLMR jungle address
feeTokenAddress: '0xd10078fdbc835726c79533a4a19db40cfad69d7f', // GLMB address
feeAmountPerSecond: etherPerDayToWeiPerSecond('0'),
deadline: 1714599360,
minDuration: 0,
roles: [USER_ROLE_MOONBEAM],
rolesData: [EMPTY_BYTES],
}
await callContractFunction(CONTRACT_NAME, CONTRACT_FUNCTION, [RENTAL_OFFER])
}

main()
.then(() => {
print(colors.bigSuccess, 'All done!')
})
.catch(error => {
console.error(error)
process.exitCode = 1
})
1 change: 1 addition & 0 deletions utils/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { ethers } from 'hardhat'

export const abi = AbiCoder.defaultAbiCoder()
export const USER_ROLE = ethers.keccak256(ethers.toUtf8Bytes('USER_ROLE'))
export const USER_ROLE_MOONBEAM = ethers.keccak256(ethers.toUtf8Bytes('User()'))
export const UNIQUE_ROLE = ethers.keccak256(ethers.toUtf8Bytes('UNIQUE_ROLE'))
export const PLAYER_ROLE = ethers.keccak256(ethers.toUtf8Bytes('Player()'))

0 comments on commit cbdc763

Please sign in to comment.