-
Notifications
You must be signed in to change notification settings - Fork 1
/
getRigsToPark.ts
191 lines (179 loc) · 4.8 KB
/
getRigsToPark.ts
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import { network, rigsDeployment } from "hardhat";
import { Database } from "@tableland/sdk";
const db = new Database();
// Blur API response
type BlurRig = {
id: string; // Rig tokenId
isSuspicious: boolean;
owner: string;
contractAddress: string;
tokenId: string;
imageUrl: string;
price: string;
priceUnit: string;
createdAt: string;
updatedAt: string;
};
// OpenSea API response
type OsRig = {
order_hash: string;
chain: string;
type: string;
price: {
current: {
currency: string;
decimals: number;
value: string;
};
};
protocol_data: {
parameters: {
offerer: string;
offer: Array<{
itemType: number;
token: string;
identifierOrCriteria: string; // Rig tokenId
startAmount: string;
endAmount: string;
}>;
consideration: Array<{
itemType: number;
token: string;
identifierOrCriteria: string;
startAmount: string;
endAmount: string;
recipient: string;
}>;
startTime: string;
endTime: string;
orderType: number;
zone: string;
zoneHash: string;
salt: string;
conduitKey: string;
totalOrginalConsiderationItems: number;
counter: number;
};
signature: string | null;
};
protocol_address: string;
};
// LooksRare API
type LooksRareRig = {
id: string;
hash: string;
quoteType: number;
globalNonce: string;
subsetNonce: string;
orderNonce: string;
collection: string;
currency: string;
signer: string;
strategyId: number;
collectionType: number;
startTime: number;
endTime: number;
price: string;
additionalParameters: string;
signature: string;
createdAt: string;
merkleRoot: null;
merkleProof: null;
amounts: Array<string>;
itemIds: Array<string>; // Rig tokenId
status: string;
};
async function getInFlight(rigIds: number[]): Promise<number[]> {
// Get the sessions where end_time is null, there should only ever be one of these
const res = await db
.prepare(
`SELECT rig_id FROM ${
rigsDeployment.pilotSessionsTable
} WHERE rig_id in (${rigIds.join(",")}) AND end_time is null;`
)
.all<{ rig_id: number }>();
const ids: number[] = [];
(res && res.results ? res.results : []).forEach((i) => {
ids.push(i.rig_id);
});
return ids;
}
async function main() {
console.log(
`\nGetting listed rigs that are in-flight on '${network.name}'...`
);
// Get contract address
if (rigsDeployment.contractAddress === "") {
throw Error(`no contractAddress entry for '${network.name}'`);
}
console.log(`Using address '${rigsDeployment.contractAddress}'`);
// Get listings on Blur
const blurReq = await fetch(
"https://openblur.p.rapidapi.com/listings?" +
new URLSearchParams({
contractAddress: rigsDeployment.contractAddress.toLowerCase(),
orderBy: "ASC",
pageSize: "100",
}),
{
headers: {
"X-RapidAPI-Key": process.env.OPENBLUR_API_KEY!,
"X-RapidAPI-Host": "openblur.p.rapidapi.com",
},
}
);
const blurRes = await blurReq.json();
const blurListed: BlurRig[] = blurRes.items || [];
// Get listings on OpenSea
const osSlug = "tableland-rigs"; // Must query by OS slug, not contract address
const osReq = await fetch(
`https://api.opensea.io/v2/listings/collection/${osSlug}/all`,
{
headers: {
accept: "application/json",
"X-API-KEY": process.env.OPENSEA_API_KEY!,
},
}
);
const osRes = await osReq.json();
const osListed: OsRig[] = osRes.listings;
// Get listings on LooksRare
const lrReq = await fetch(
`https://api.looksrare.org/api/v2/orders?quoteType=1&collection=${rigsDeployment.contractAddress}&status=VALID`,
{
headers: {
accept: "application/json",
"X-Looks-Api-Key": process.env.LOOKSRARE_API_KEY!,
},
}
);
const lrRes = await lrReq.json();
const lrListed: LooksRareRig[] = lrRes.data;
// Check if Rigs are in-flight on each marketplace
const blurIds = blurListed.map((l) => {
return parseInt(l.tokenId);
});
const osIds =
osListed.map((l) => {
return parseInt(l.protocol_data.parameters.offer[0].identifierOrCriteria);
}) || [];
const lrIds =
lrListed.map((l) => {
return parseInt(l.itemIds[0]);
}) || [];
const blurToPark = await getInFlight(blurIds);
const osToPark = await getInFlight(osIds);
const lrToPark = await getInFlight(lrIds);
console.log(
`----\nForce park Rigs:\n`,
`Blur: ${blurToPark.length > 0 ? blurToPark.join(",") : "none"}\n`,
`OpenSea: ${osToPark.length > 0 ? osToPark.join(",") : "none"}\n`,
`LooksRare: ${lrToPark.length > 0 ? lrToPark.join(",") : "none"}`
);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});