forked from Moridi/axelar-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauction.js
60 lines (48 loc) · 1.98 KB
/
auction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const {
getDefaultProvider,
Contract,
constants: { AddressZero },
utils: { keccak256, defaultAbiCoder },
Wallet,
} = require('ethers');
const {
utils: { deployContract },
} = require('@axelar-network/axelar-local-dev');
const ERC721 = rootRequire('./artifacts/examples/evm/nft-auctionhouse/ERC721Demo.sol/ERC721Demo.json');
const NftAuctionhouse = rootRequire('./artifacts/examples/evm/nft-auctionhouse/NftAuctionhouseRemote.sol/NftAuctionhouseRemote.json');
async function auction(chain, privateKey, tokenId, deadline, min) {
deadline = deadline || Math.floor(new Date().getTime() / 1000 + 60);
min = min || 0;
const provider = getDefaultProvider(chain.rpc);
const wallet = new Wallet(privateKey, provider);
const erc721 = new Contract(chain.erc721, ERC721.abi, wallet);
const auctionhouse = new Contract(chain.contract.address, NftAuctionhouse.abi, wallet);
await (await erc721.approve(auctionhouse.address, tokenId)).wait();
await (await auctionhouse.auction(erc721.address, tokenId, min, deadline)).wait();
}
module.exports = auction;
if (require.main === module) {
const env = process.argv[2];
if (env == null || (env !== 'testnet' && env !== 'local'))
throw new Error('Need to specify tesntet or local as an argument to this script.');
let temp;
if (env == 'local') {
temp = require(`../../../chain-config/local.json`);
} else {
try {
temp = require(`@axelar-network/axelar-cgp-solidity/info/testnet.json`);
} catch {
temp = testnetInfo;
}
}
const chains = temp;
const args = process.argv.slice(3);
const chainName = args[0];
const privateKey = args[1];
const tokenId = BigInt(args[2]);
const chain = chains.find((chain) => chain.name == chainName);
const deadline = BigInt(args[3] || Math.floor(new Date().getTime() / 1000 + 60));
const min = BigInt(args[4] || 0);
auction(chain, privateKey, tokenId, deadline, min);
}