-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from neatonk/kevin/add-zora-editions
add zora drops strategies
- Loading branch information
Showing
8 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// @format | ||
import { callTokenUriFactory } from "../../strategy-factories/call-tokenuri/extractor.mjs"; | ||
|
||
export const version = "0.0.1"; | ||
export const name = "zora-drops-call-tokenuri"; | ||
export const props = { | ||
version, | ||
strategyName: name, | ||
signature: { | ||
name: "tokenURI", | ||
type: "function", | ||
inputs: [ | ||
{ | ||
name: "tokenId", | ||
type: "uint256", | ||
}, | ||
], | ||
}, | ||
filterFunc: ({ platform }) => platform.name === "zora-drops", | ||
}; | ||
|
||
const { init, update } = callTokenUriFactory(props); | ||
|
||
export { init, update }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @format | ||
import { decodeSolidityHexStringFactory } from "../../strategy-factories/decode-solidity-hex-string-factory/transformer.mjs"; | ||
|
||
export const name = "zora-drops-call-tokenuri"; | ||
export const version = "0.1.0"; | ||
|
||
const resultKey = "tokenURI"; | ||
|
||
const { onClose, onError, onLine } = decodeSolidityHexStringFactory({ | ||
strategyName: name, | ||
version, | ||
resultKey, | ||
}); | ||
|
||
export { onClose, onError, onLine }; |
80 changes: 80 additions & 0 deletions
80
src/strategies/zora-drops-filter-contracts/transformer.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// @format | ||
import { decodeLog } from "eth-fun"; | ||
|
||
import logger from "../../logger.mjs"; | ||
import { parseJSON } from "../../utils.mjs"; | ||
|
||
export const name = "zora-drops-filter-contracts"; | ||
const log = logger(name); | ||
export const version = "0.1.0"; | ||
|
||
export function onClose() { | ||
log("closed"); | ||
return; | ||
} | ||
|
||
export function onError(error) { | ||
log(error.toString()); | ||
throw error; | ||
} | ||
|
||
function decodeDropLog(log) { | ||
const topics = log.topics; | ||
topics.shift(); | ||
const result = decodeLog( | ||
// index_topic_1 address creator, index_topic_2 address editionContractAddress, uint256 editionSize | ||
[ | ||
{ | ||
type: "address", | ||
name: "creator", | ||
indexed: true, | ||
}, | ||
{ | ||
type: "address", | ||
name: "editionContractAddress", | ||
indexed: true, | ||
}, | ||
{ | ||
type: "uint256", | ||
name: "editionSize", | ||
}, | ||
], | ||
log.data, | ||
topics | ||
); | ||
|
||
if (result) { | ||
for (const k of ["creator", "editionContractAddress"]) { | ||
result[k] = result?.[k].toLowerCase?.(); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export function onLine(line, editionsFactoryAddress, createEventSelector) { | ||
let logs; | ||
try { | ||
logs = parseJSON(line, 100); | ||
} catch (err) { | ||
log(err); | ||
return; | ||
} | ||
let contracts = {}; | ||
for (const log of logs) { | ||
if ( | ||
log.address === editionsFactoryAddress && | ||
log.topics[0] === createEventSelector | ||
) { | ||
const { editionContractAddress } = decodeDropLog(log); | ||
contracts[editionContractAddress] = { | ||
name: "zora-drops", | ||
}; | ||
} | ||
} | ||
|
||
if (Object.keys(contracts).length === 0) { | ||
return ""; | ||
} | ||
return JSON.stringify(contracts); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"address":"0x5ba2cae53603fc0e533fc19765ad09e2dc414de6","tokenId":"1","createdAtBlockNumber":15610515,"platform":{"name":"zora-drops"}}] |
7 changes: 7 additions & 0 deletions
7
test/strategies/zora-drops-call-tokenuri/extractor_snapshot.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"inputs": ["./extractor_input_data"], | ||
"expect": { | ||
"write": "{\"metadata\":{\"block\":{\"number\":15610515},\"contract\":{\"address\":\"0x5ba2cae53603fc0e533fc19765ad09e2dc414de6\"},\"tokenId\":\"1\"},\"results\":\"0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000609646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c65794a755957316c496a6f67496c526f5a53424e5a584a6e5a534276636a6f675347393349456b6754475668636d356c5a434230627942546447397749466476636e4a356157356e494746755a43424d62335a6c4948526f5a53424d6158463161575167553342736158527a494445694c4341695a47567a59334a7063485270623234694f6941694e5334324e794246564567676432467a49484e3064574e7249476c754946526f5a53424e5a584a6e5a53424462323530636d466a6443416f4a4463734e544d334c6a41354b533563626c78756447686c4947316c6257567a4f6944776e366167584734744946526f5a53424e5a584a6e5a5678754c53424d6158463161575167553342736158527a584734744945564a554449354d6a6c63626c78756432686c636d55675353426d59576c735a575136495043666d4a4e63626930675353426d59576c735a575167644738676132357664794230636d467563325a6c6369426f59584d675953427a64484a70593351675a32467a4c57787062576c304947396d494449734d7a41775847347449456b675a6d46706247566b49485276494864796158526c4947456764326c306147527959586367625756306147396b4948526f59585167643239796132566b4948647064476767553239755a7931424c555268655342455155386e63794248626d397a61584d675532466d5a5678754c53424a49475a686157786c5a4342306279426964576c735a43426849484e766248563061573975494864706447676752556c514d6a6b794f56787558473533614756795a53424a49484e3159324e6c5a57526c5a446f675847347449456b676432467a626964304947466d636d46705a434230627942685a4731706443424a49475a686157786c5a43416d4947467a6179426d6233496761475673634678754c53424a4947356c646d567949476468646d55676458417549456b676132567764434230636e6c70626d636764573530615777754c69356362693067535342475431564f5243424249464e50544656555355394f495043666a496863626c78755157787349475a31626d527a49484a6c59325670646d566b49475a79623230676447687063794277636d39715a574e30494746795a53426b61585a705a47566b4948567a6157356e49444234553342736158527a4f6c78754c53424d615846316157516755334273615851364946526f5a53424e5a584a6e5a5678754c5342466447686c636d56316253424462334a6c4945526c646e4e6362693067553239755a7942684945526865534245515539636269306762586c7a5a57786d4943686a636d5668644739794b5678754c5342546347787064446f674d4867774d6b59354e454d354f5464444e7a6730596b4979597a6b304e7a4e454d7a41344e5449774f4441334d6d4d324e6a6c465a44513358473563626b5a3162477767566d6c6b5a5738676232346757573931564856695a546f67384a2b4f724678756148523063484d364c79393562335630645335695a533977656d55325444637853576f35637941694c434169615731685a3255694f6941696158426d637a6f764c324a685a6d74795a576c6b4e33467862584273626d5530596a52795a324a7559545a6f596d7033646d4675656e4e715a47673164445632654855334d3267335a6a597a62476c36656e64316147567450326c6b505445694c434169595735706257463061573975583356796243493649434a7063475a7a4f693876596d466d65574a6c61574a71646e5a30636e557a5932397463476474626a4a324e48567a5a6d56785a5842734e6a52684e5846344e33427a63334d3061474e32646d466e615756726348566d5a57452f615751394d53497349434a77636d39775a584a306157567a496a6f6765794a75645731695a5849694f6941784c434169626d46745a53493649434a5561475567545756795a32556762334936494568766479424a4945786c59584a755a57516764473867553352766343425862334a7965576c755a794268626d5167544739325a5342306147556754476c7864576c6b49464e7762476c3063794a3966513d3d0000000000000000000000000000000000000000000000\"}\n" | ||
|
||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
test/strategies/zora-drops-call-tokenuri/extractor_test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// @format | ||
import fs from "fs/promises"; | ||
import { resolve, dirname } from "path"; | ||
import { fileURLToPath } from "url"; | ||
|
||
import test from "ava"; | ||
|
||
import snapshotExtractor from "../../../utils/snapshot_extractor.mjs"; | ||
import * as extractor from "../../../src/strategies/zora-drops-call-tokenuri/extractor.mjs"; | ||
|
||
test("zora-drops-call-tokenuri extractor", async (t) => { | ||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
const snapshot = JSON.parse( | ||
await fs.readFile(resolve(__dirname, "./extractor_snapshot.json")) | ||
); | ||
|
||
snapshot.inputs[0] = resolve(__dirname, snapshot.inputs[0]); | ||
|
||
const result = await snapshotExtractor(extractor, snapshot); | ||
// console.log(JSON.stringify(result)); | ||
t.deepEqual(JSON.parse(result), JSON.parse(snapshot.expect.write)); | ||
}); |
30 changes: 30 additions & 0 deletions
30
test/strategies/zora-drops-call-tokenuri/transformer_test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//@format | ||
import fs from "fs"; | ||
import { resolve, dirname } from "path"; | ||
import { fileURLToPath } from "url"; | ||
|
||
import test from "ava"; | ||
|
||
import { onLine } from "../../../src/strategies/zora-drops-call-tokenuri/transformer.mjs"; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
const snapshot = JSON.parse( | ||
fs.readFileSync(resolve(__dirname, "./extractor_snapshot.json")) | ||
); | ||
|
||
test("zora-drops-call-tokenuri transformer", (t) => { | ||
const write = onLine(snapshot.expect.write); | ||
const expected = { | ||
metadata: { | ||
block: { number: 15610515 }, | ||
contract: { | ||
address: "0x5ba2cae53603fc0e533fc19765ad09e2dc414de6", | ||
}, | ||
tokenId: "1", | ||
}, | ||
tokenURI: | ||
"data:application/json;base64,eyJuYW1lIjogIlRoZSBNZXJnZSBvcjogSG93IEkgTGVhcm5lZCB0byBTdG9wIFdv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Wo5cyAiLCAiaW1hZ2UiOiAiaXBmczovL2JhZmtyZWlkN3FxbXBsbmU0YjRyZ2JuYTZoYmp3dmFuenNqZGg1dDV2eHU3M2g3ZjYzbGl6end1aGVtP2lkPTEiLCAiYW5pbWF0aW9uX3VybCI6ICJpcGZzOi8vYmFmeWJlaWJqdnZ0cnUzY29tcGdtbjJ2NHVzZmVxZXBsNjRhNXF4N3Bzc3M0aGN2dmFnaWVrcHVmZWE/aWQ9MSIsICJwcm9wZXJ0aWVzIjogeyJudW1iZXIiOiAxLCAibmFtZSI6ICJUaGUgTWVyZ2Ugb3I6IEhvdyBJIExlYXJuZWQgdG8gU3RvcCBXb3JyeWluZyBhbmQgTG92ZSB0aGUgTGlxdWlkIFNwbGl0cyJ9fQ==", | ||
}; | ||
t.is(write, JSON.stringify(expected)); | ||
}); |
76 changes: 76 additions & 0 deletions
76
test/strategies/zora-drops-filter-contracts/transformer_test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//@format | ||
import test from "ava"; | ||
|
||
import { onLine } from "../../../src/strategies/zora-drops-filter-contracts/transformer.mjs"; | ||
|
||
const dropsFactoryAddress = | ||
"0x000000000000000000000000f74b146ce44cc162b601dec3be331784db111dc1"; | ||
const createEventSelector = | ||
"0xad59ebba8bfb06ba01a615a611467ca3bef86a275bd5e9704d3b295112550ba5"; | ||
|
||
const dummyAddress = | ||
"0x0000000000000000000000000000000000000000000000000000000000000001"; | ||
const dummyTopics = [createEventSelector, dummyAddress, dummyAddress]; | ||
|
||
const genLog = ({ address = dropsFactoryAddress, topics = dummyTopics }) => { | ||
return { | ||
address, | ||
topics, | ||
data: "0x0000000000000000000000000000000000000000000000000000000000000001", | ||
blockNumber: "0xEE507D", | ||
transactionHash: | ||
"0x0x5051986fe20110d6a9cc1705af48993bf435700f28e23dc85130f4808e7BOGUS", | ||
transactionIndex: "0x123", | ||
blockHash: | ||
"0x0036bcde6797dfa4f77a0e72b928d6ced6f8858e6b0025c8b837e02081aBOGUS", | ||
logIndex: "0x123", | ||
removed: false, | ||
}; | ||
}; | ||
|
||
test("if zora-drops-filter-contracts transformer emits new edition contract address", (t) => { | ||
const creator = | ||
"0x000000000000000000000000cfbf34d385ea2d5eb947063b67ea226dcda3dc38"; | ||
const editionContractAddress = | ||
"0x0000000000000000000000005ba2cae53603fc0e533fc19765ad09e2dc414de6"; | ||
const editionContractAddressDec = | ||
"0x5ba2cae53603fc0e533fc19765ad09e2dc414de6"; | ||
|
||
const snapshot = [ | ||
genLog({ topics: [createEventSelector, creator, editionContractAddress] }), | ||
]; | ||
|
||
const res = onLine( | ||
JSON.stringify(snapshot), | ||
dropsFactoryAddress, | ||
createEventSelector | ||
); | ||
|
||
t.deepEqual(JSON.parse(res), { | ||
[editionContractAddressDec]: { name: "zora-drops" }, | ||
}); | ||
}); | ||
|
||
test("if zora-drops-filter-contracts transformer ignores unrelated logs", (t) => { | ||
const snapshot = [ | ||
// Unrelated factory address | ||
genLog({ address: dummyAddress }), | ||
|
||
// unrelated event topic | ||
genLog({ | ||
topics: [ | ||
"0xf889a5cdc62274389379cbfade0f225b1d30b7395177fd6aeaab61662b1c6edf", | ||
dummyAddress, | ||
dummyAddress, | ||
], | ||
}), | ||
]; | ||
|
||
const res = onLine( | ||
JSON.stringify(snapshot), | ||
dropsFactoryAddress, | ||
createEventSelector | ||
); | ||
|
||
t.is(res, ""); | ||
}); |