-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreate-order-auction.js
More file actions
90 lines (78 loc) · 2.71 KB
/
create-order-auction.js
File metadata and controls
90 lines (78 loc) · 2.71 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { parseEther, Wallet } from "ethers";
import {
getAxieIdsFromAccount,
approveMarketplaceContract,
createMarketplaceOrder,
createProvider,
} from "axie-tools";
import "dotenv/config";
async function auction() {
if (
!process.env.PRIVATE_KEY ||
!process.env.MARKETPLACE_ACCESS_TOKEN ||
!process.env.SKYMAVIS_API_KEY
) {
throw new Error(
"Please set PRIVATE_KEY, MARKETPLACE_ACCESS_TOKEN, and SKYMAVIS_API_KEY in a .env file",
);
}
const provider = createProvider(process.env.SKYMAVIS_API_KEY);
const wallet = new Wallet(process.env.PRIVATE_KEY, provider);
const address = await wallet.getAddress();
// Get CLI args: axieId startPrice endPrice durationInHours
const args = process.argv.slice(2);
const axieId = parseInt(args[0], 10);
const startPrice = args[1];
const endPrice = args[2];
const durationHours = parseInt(args[3], 10);
if (isNaN(axieId) || axieId < 1) {
throw new Error("Please provide a valid axieID as the first argument");
}
if (!startPrice || !endPrice || isNaN(startPrice) || isNaN(endPrice)) {
throw new Error("Please provide valid start and end prices in WETH");
}
if (isNaN(durationHours) || durationHours < 1 || durationHours > 168) {
throw new Error("Please provide a valid duration in hours (1-168)");
}
// Check axie ownership
const axieIds = await getAxieIdsFromAccount(address, provider);
if (!axieIds.includes(axieId)) {
throw new Error(`Axie ${axieId} is not owned by ${address}`);
}
// Ensure marketplace contract is approved
await approveMarketplaceContract(wallet);
// Prepare auction data
const currentBlock = await provider.getBlock("latest");
const startedAt = currentBlock.timestamp;
const endedAt = startedAt + durationHours * 3600; // convert hours to seconds
const expiredAt = startedAt + 15634800; // ~6 months (max allowed)
const orderData = {
address,
axieId: axieId.toString(),
basePrice: parseEther(startPrice).toString(),
endedPrice: parseEther(endPrice).toString(),
startedAt,
endedAt,
expiredAt,
};
// Create the auction
const result = await createMarketplaceOrder(
orderData,
process.env.MARKETPLACE_ACCESS_TOKEN,
wallet,
process.env.SKYMAVIS_API_KEY,
);
if (result === null || result.errors || !result.data) {
throw new Error(
result?.errors?.[0]?.message || "Unknown error creating auction",
);
}
console.log(`✅ Created auction for Axie ${axieId}!`);
console.log(`Start price: ${startPrice} WETH`);
console.log(`End price: ${endPrice} WETH`);
console.log(`Duration: ${durationHours} hours`);
console.log(
`Current price in USD: ${result.data.createOrder.currentPriceUsd}`,
);
}
auction().catch(console.error);