Skip to content

Commit

Permalink
rental offer scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Nov 27, 2023
1 parent 9b10825 commit 58639da
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
48 changes: 48 additions & 0 deletions scripts/04-create-offer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ethers, network as hardhatNetwork } from 'hardhat'
import config, { Network } from '../addresses'
import { colors, print, confirmOrDie } from '../utils/misc'
import { RentalOffer } from '../utils/types'
import { AddressZero, EMPTY_BYTES, ONE_DAY } from '../utils/constants'
import { randomBytes } from 'crypto'
import { toWei } from '../utils/bignumber'
import { USER_ROLE } from '../utils/roles'

async function main() {
const NETWORK = hardhatNetwork.name as Network
const CONTRACT_NAME = 'OriumMarketplace'
const CONTRACT_ADDRESS = config[NETWORK][CONTRACT_NAME].address

await confirmOrDie(
`Are you sure you want to create a rental offer ${config[NETWORK].RolesRegistry.address} for ${CONTRACT_NAME} on ${NETWORK} network?`,
)

const contract = await ethers.getContractAt(CONTRACT_NAME, CONTRACT_ADDRESS)

const blockTimestamp = (await ethers.provider.getBlock('latest')).timestamp

const rentalOffer: RentalOffer = {
nonce: `0x${randomBytes(32).toString('hex')}`,
lender: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906',
borrower: AddressZero,
tokenAddress: '0x86935F11C86623deC8a25696E1C19a8659CbF95d',
tokenId: 13477, //13477,
feeTokenAddress: '0x385Eeac5cB85A38A9a07A70c73e0a3271CfB54A7',
feeAmountPerSecond: toWei('0.999999999907421'),
deadline: blockTimestamp + ONE_DAY,
roles: [USER_ROLE],
rolesData: [EMPTY_BYTES],
}
const tx = await contract.createRentalOffer(rentalOffer)

print(colors.highlight, `Transaction hash: ${tx.hash}`)
print(colors.success, `Created rental offer in ${CONTRACT_NAME} on ${NETWORK} network!`)
}

main()
.then(() => {
console.log('Done!')
})
.catch(error => {
console.error(error)
process.exitCode = 1
})
30 changes: 30 additions & 0 deletions scripts/05-cancel-offer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ethers, network as hardhatNetwork } from 'hardhat'
import config, { Network } from '../addresses'
import { colors, print, confirmOrDie } from '../utils/misc'

async function main() {
const NETWORK = hardhatNetwork.name as Network
const CONTRACT_NAME = 'OriumMarketplace'
const CONTRACT_ADDRESS = config[NETWORK][CONTRACT_NAME].address

await confirmOrDie(
`Are you sure you want to cancel a rental offer ${config[NETWORK].RolesRegistry.address} for ${CONTRACT_NAME} on ${NETWORK} network?`,
)

const contract = await ethers.getContractAt(CONTRACT_NAME, CONTRACT_ADDRESS)

const nonce = '71870379709915352622008287115212578751761046896364388794105918647859783855919'
const tx = await contract.cancelRentalOffer(nonce)

print(colors.highlight, `Transaction hash: ${tx.hash}`)
print(colors.success, `Cancelled rental offer in ${CONTRACT_NAME} on ${NETWORK} network!`)
}

main()
.then(() => {
console.log('Done!')
})
.catch(error => {
console.error(error)
process.exitCode = 1
})

0 comments on commit 58639da

Please sign in to comment.