-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreate-order.js
More file actions
83 lines (71 loc) · 2.21 KB
/
create-order.js
File metadata and controls
83 lines (71 loc) · 2.21 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
import { parseEther, Wallet } from "ethers";
import {
getAxieIdsFromAccount,
approveMarketplaceContract,
createMarketplaceOrder,
createProvider,
} from "axie-tools";
import "dotenv/config";
async function sale() {
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 axieId from command line args
const args = process.argv.slice(2);
const axieId = parseInt(args[0], 10);
if (isNaN(axieId) || axieId < 1) {
throw new Error("Please provide a valid axieID as the first argument");
}
// Get price from command line args (in WETH)
const price = args[1];
if (!price || isNaN(price)) {
throw new Error(
"Please provide a valid price in WETH as the second argument",
);
}
// Check if the axieId is owned by the wallet
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 order data
const currentBlock = await provider.getBlock("latest");
const startedAt = currentBlock.timestamp;
const expiredAt = startedAt + 15634800; // ~6 months
const orderData = {
address,
axieId: axieId.toString(),
basePrice: parseEther(price).toString(),
endedPrice: "0",
startedAt,
endedAt: 0,
expiredAt,
};
// Create the order
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 order",
);
}
console.log(
`✅ Listed Axie ${axieId}! Current price in USD: ${result.data.createOrder.currentPriceUsd}`,
);
}
sale().catch(console.error);