-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
410 additions
and
197 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { DeflatedTraits, EncodedTrait } from "../types/artwork.js"; | ||
import { deflateTraits } from "./deflateTraits.js"; | ||
|
||
describe("encoded traits deflating", () => { | ||
test("deflate encoded traits", () => { | ||
// taken from https://github.com/nounsDAO/nouns-monorepo/blob/f98cbbafded212026c05ff75e337b2e9e0cdfab0/packages/nouns-assets/src/image-data.json#L1939-L2032 | ||
// disregarding the last two noggles that were added after the transaction below | ||
const descriptorV2Glasses: EncodedTrait[] = [ | ||
"0x000b1710070300062101000621030001210202022401210100012102020224052102020224032102020224052102020224032102020224022102000121020202240121010001210202022401210300062101000621", | ||
"0x000b17100703000624010006240300012402020265012401000124020202650524020202650324020202650224020001240202026501240100012402020265022402000124020202650124010001240202026501240300062401000624", | ||
"0x000b1710070300062401000624030003240165022401000324016513240200012401660224015b01240100012401660224015b022402000624010006240300062401000624", | ||
"0x000b171007030006240100062403000124020203240100012402020724020205240202042402000124020203240100012402020424020001240202032401000124020203240300062401000624", | ||
"0x000b17100703000644010006440300014402020224014401000144020202240544020202240344020202240244020001440202022401440100014402020224024402000144020202240144010001440202022401440300064401000644", | ||
"0x000b17100703000607010006070300010702020224010701000107020202240507020202240307020202240207020001070202022401070100010702020224020702000107020202240107010001070202022401070300060701000607", | ||
"0x000b171007030006c0010006c0030001c00202022401c0010001c00202022405c00202022403c00202022402c0020001c00202022401c0010001c00202022402c0020001c00202022401c0010001c00202022401c0030006c0010006c0", | ||
"0x000b1710070300062401000624030004240102012401000424010208240102062401020224020006240100072402000624010006240300062401000624", | ||
"0x000b171007030006100100068c030001100202022401100100018c02020224048c0110020202240110028c02020224028c020001100202022401100100018c02020224028c020001100202022401100100018c02020224018c030006100100068c", | ||
"0x000b171007030006c8010006c8030001c80202022401c8010001c80202022405c80202022403c80202022402c8020001c80202022401c8010001c80202022402c8020001c80202022401c8010001c80202022401c8030006c8010006c8", | ||
"0x000b17100703000638010006380300013802020224013801000138020202240538020202240338020202240238020001380202022401380100013802020224023802000138020202240138010001380202022401380300063801000638", | ||
"0x000b171007030006de010006de030001de0202022401de010001de0202022405de0202022403de0202022402de020001de0202022401de010001de0202022402de020001de0202022401de010001de0202022401de030006de010006de", | ||
"0x000b17100703000609010006090300010902020224010901000109020202240509020202240309020202240209020001090202022401090100010902020224020902000109020202240109010001090202022401090300060901000609", | ||
"0x000b17100703000615010006150300011502020224011501000115020202240515020202240315020202240215020001150202022401150100011502020224021502000115020202240115010001150202022401150300061501000615", | ||
"0x000b171007030006210100069b030001210202022401210100019b02020224049b0121020202240121029b02020224029b020001210202022401210100019b02020224029b020001210202022401210100019b02020224019b030006210100069b", | ||
"0x000b17100703000625010006250300012502020224012501000125020202240525020202240325020202240225020001250202022401250100012502020224022502000125020202240125010001250202022401250300062501000625", | ||
"0x000b1710070300065a0100065a0300015a02670224015a0100015a02670224055a02670224035a02670224025a0200015a02670224015a0100015a02670224025a0200015a02670224015a0100015a02670224015a0300065a0100065a", | ||
"0x000b1710070300061d0100061d0300011d02020224011d0100011d02020224051d02020224031d02020224021d0200011d02020224011d0100011d02020224021d0200011d02020224011d0100011d02020224011d0300061d0100061d", | ||
"0x000b171007030006a1010006a1030001a10202022401a1010001a10202022405a10202022403a10202022402a1020001a10202022401a1010001a10202022402a1020001a10202022401a1010001a10202022401a1030006a1010006a1", | ||
"0x000b1710070300062701000614030001270202022401270100011402020224041401270202022401270214020202240214020001270202022401270100011402020224021402000127020202240127010001140202022401140300062701000614", | ||
"0x000b17100703000629010006290300012902020224012901000129020202240529020202240329020202240229020001290202022401290100012902020224022902000129020202240129010001290202022401290300062901000629", | ||
]; | ||
|
||
// taken from https://etherscan.io/tx/0xdeb47c93142213cac09c2937191c597fa5dcddf9e8ba5c7c5efda9a226f66547 | ||
const expectedDeflatedGlasses: DeflatedTraits = { | ||
data: "0xa555318e1a4110dcee6158d65c8064902324232d3af103124b0e70e8d00996830b6c7fc30fe00724e62784bc02f9292e6aaed199196fb3f64a5bdb5ddd5d35b33b88aaeabcde7697ab5977597f76d783a31f9cf981333f70e6a3331f9df9a1333ffcd15daf9df9daf11f39f32367be71e61b67fed57ba77eecae8f9df9b133ffe0cc3ffceaae579faaf19b491daae14270874a16aada0ab2144562c8625d68d62b0bd3714c5f5c5fccbfc55c0bff164a5f05598a223110e19ad54b9cb4a6e7fb7fb8f10fad4053f87c4d6df986fc73524ff1c5d3faeff5f9dbf5b1b0fff0bc931af765ff83e73d1a7f9b87ff58c7f5fd6f30bf81ff865f12598a22311075a359bdc4c9c6f47af8d7e8c7536a2a204b512406a2d69ad54b9c5cf57af81fd17f84ff910ac852148981a847cdea254e8ea6e7fbbfbbf9fe8356f472d62ecf116ef06ae7adfe8773f764fa13f4efb0bf0957884c769768b033469903b39e12273bd3f4d7d0755ddfff095a27acef447564298ac440d49366f5122727d3ebe1bf46ff1afe6b2a204b512406a2ae35ab9738599b5e0fff33facff03f5301598a223110f5ac59bdc4c9d9f47af837e86fe0df5001598a223110b5d1ac5ee2a431bd1efe33f4cfe03fa302b214456220ea4cb37a899399e9f9fe4f2ffffff67ffcffedf9fbd81ba3cc81594f8993bd69fa6bb8ebfd2ca1b5c4fa96544796a2480c445d6a562f71b234bd1efe5bf46fe1bfd5ef504096a2480c44dd6a562f71b235bd1efe73f4cfe13fe70e90a528120351e79ad54b9ccc4daf87ff01fd07f81fa8802c459118887ad0ac5ee2e4607abefff57c3ea27f0aff472a209329cfe7d418650ecc7a4a9c4c4dd35fc35def6705ad15d6b7a23ab214456220ea4ab37a899395e9c1e037", | ||
originalLength: 3488n, | ||
traitCount: 21, | ||
}; | ||
|
||
const compressedGlasses = deflateTraits(descriptorV2Glasses); | ||
expect(compressedGlasses).toStrictEqual(expectedDeflatedGlasses); | ||
}); | ||
}); |
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,20 @@ | ||
import { deflateRaw } from "pako"; | ||
import { encodeAbiParameters } from "viem"; | ||
import { DeflatedTraits, EncodedTrait } from "../types/artwork.js"; | ||
|
||
export const deflateTraits = ( | ||
encodedTraits: EncodedTrait[] | ||
): DeflatedTraits => { | ||
const abiEncodedArtwork = encodeAbiParameters( | ||
[{ type: "bytes[]" }], | ||
[encodedTraits] | ||
); | ||
const data = ("0x" + | ||
Buffer.from( | ||
deflateRaw(Buffer.from(abiEncodedArtwork.substring(2), "hex")) | ||
).toString("hex")) as `0x${string}`; | ||
const originalLength = BigInt(abiEncodedArtwork.substring(2).length / 2); | ||
const traitCount = encodedTraits.length; | ||
|
||
return { data, originalLength, traitCount }; | ||
}; |
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,40 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { DeflatedTraitsData, EncodedTrait } from "../types/artwork.js"; | ||
import { inflateTraits } from "./inflateTraits.js"; | ||
|
||
describe("encoded traits inflating", () => { | ||
test("inflate encoded traits", () => { | ||
// taken from https://etherscan.io/tx/0xdeb47c93142213cac09c2937191c597fa5dcddf9e8ba5c7c5efda9a226f66547 | ||
const deflatedGlasses: DeflatedTraitsData = | ||
"0xa555318e1a4110dcee6158d65c8064902324232d3af103124b0e70e8d00996830b6c7fc30fe00724e62784bc02f9292e6aaed199196fb3f64a5bdb5ddd5d35b33b88aaeabcde7697ab5977597f76d783a31f9cf981333f70e6a3331f9df9a1333ffcd15daf9df9daf11f39f32367be71e61b67fed57ba77eecae8f9df9b133ffe0cc3ffceaae579faaf19b491daae14270874a16aada0ab2144562c8625d68d62b0bd3714c5f5c5fccbfc55c0bff164a5f05598a223110e19ad54b9cb4a6e7fb7fb8f10fad4053f87c4d6df986fc73524ff1c5d3faeff5f9dbf5b1b0fff0bc931af765ff83e73d1a7f9b87ff58c7f5fd6f30bf81ff865f12598a22311075a359bdc4c9c6f47af8d7e8c7536a2a204b512406a2d69ad54b9c5cf57af81fd17f84ff910ac852148981a847cdea254e8ea6e7fbbfbbf9fe8356f472d62ecf116ef06ae7adfe8773f764fa13f4efb0bf0957884c769768b033469903b39e12273bd3f4d7d0755ddfff095a27acef447564298ac440d49366f5122727d3ebe1bf46ff1afe6b2a204b512406a2ae35ab9738599b5e0fff33facff03f5301598a223110f5ac59bdc4c9d9f47af837e86fe0df5001598a223110b5d1ac5ee2a431bd1efe33f4cfe03fa302b214456220ea4cb37a899399e9f9fe4f2ffffff67ffcffedf9fbd81ba3cc81594f8993bd69fa6bb8ebfd2ca1b5c4fa96544796a2480c445d6a562f71b234bd1efe5bf46fe1bfd5ef504096a2480c44dd6a562f71b235bd1efe73f4cfe13fe70e90a528120351e79ad54b9ccc4daf87ff01fd07f81fa8802c459118887ad0ac5ee2e4607abefff57c3ea27f0aff472a209329cfe7d418650ecc7a4a9c4c4dd35fc35def6705ad15d6b7a23ab214456220ea4ab37a899395e9c1e037"; | ||
|
||
// taken from https://github.com/nounsDAO/nouns-monorepo/blob/f98cbbafded212026c05ff75e337b2e9e0cdfab0/packages/nouns-assets/src/image-data.json#L1939-L2032 | ||
// disregarding the last two noggles that were added after the transaction above | ||
const expectedTraits: EncodedTrait[] = [ | ||
"0x000b1710070300062101000621030001210202022401210100012102020224052102020224032102020224052102020224032102020224022102000121020202240121010001210202022401210300062101000621", | ||
"0x000b17100703000624010006240300012402020265012401000124020202650524020202650324020202650224020001240202026501240100012402020265022402000124020202650124010001240202026501240300062401000624", | ||
"0x000b1710070300062401000624030003240165022401000324016513240200012401660224015b01240100012401660224015b022402000624010006240300062401000624", | ||
"0x000b171007030006240100062403000124020203240100012402020724020205240202042402000124020203240100012402020424020001240202032401000124020203240300062401000624", | ||
"0x000b17100703000644010006440300014402020224014401000144020202240544020202240344020202240244020001440202022401440100014402020224024402000144020202240144010001440202022401440300064401000644", | ||
"0x000b17100703000607010006070300010702020224010701000107020202240507020202240307020202240207020001070202022401070100010702020224020702000107020202240107010001070202022401070300060701000607", | ||
"0x000b171007030006c0010006c0030001c00202022401c0010001c00202022405c00202022403c00202022402c0020001c00202022401c0010001c00202022402c0020001c00202022401c0010001c00202022401c0030006c0010006c0", | ||
"0x000b1710070300062401000624030004240102012401000424010208240102062401020224020006240100072402000624010006240300062401000624", | ||
"0x000b171007030006100100068c030001100202022401100100018c02020224048c0110020202240110028c02020224028c020001100202022401100100018c02020224028c020001100202022401100100018c02020224018c030006100100068c", | ||
"0x000b171007030006c8010006c8030001c80202022401c8010001c80202022405c80202022403c80202022402c8020001c80202022401c8010001c80202022402c8020001c80202022401c8010001c80202022401c8030006c8010006c8", | ||
"0x000b17100703000638010006380300013802020224013801000138020202240538020202240338020202240238020001380202022401380100013802020224023802000138020202240138010001380202022401380300063801000638", | ||
"0x000b171007030006de010006de030001de0202022401de010001de0202022405de0202022403de0202022402de020001de0202022401de010001de0202022402de020001de0202022401de010001de0202022401de030006de010006de", | ||
"0x000b17100703000609010006090300010902020224010901000109020202240509020202240309020202240209020001090202022401090100010902020224020902000109020202240109010001090202022401090300060901000609", | ||
"0x000b17100703000615010006150300011502020224011501000115020202240515020202240315020202240215020001150202022401150100011502020224021502000115020202240115010001150202022401150300061501000615", | ||
"0x000b171007030006210100069b030001210202022401210100019b02020224049b0121020202240121029b02020224029b020001210202022401210100019b02020224029b020001210202022401210100019b02020224019b030006210100069b", | ||
"0x000b17100703000625010006250300012502020224012501000125020202240525020202240325020202240225020001250202022401250100012502020224022502000125020202240125010001250202022401250300062501000625", | ||
"0x000b1710070300065a0100065a0300015a02670224015a0100015a02670224055a02670224035a02670224025a0200015a02670224015a0100015a02670224025a0200015a02670224015a0100015a02670224015a0300065a0100065a", | ||
"0x000b1710070300061d0100061d0300011d02020224011d0100011d02020224051d02020224031d02020224021d0200011d02020224011d0100011d02020224021d0200011d02020224011d0100011d02020224011d0300061d0100061d", | ||
"0x000b171007030006a1010006a1030001a10202022401a1010001a10202022405a10202022403a10202022402a1020001a10202022401a1010001a10202022402a1020001a10202022401a1010001a10202022401a1030006a1010006a1", | ||
"0x000b1710070300062701000614030001270202022401270100011402020224041401270202022401270214020202240214020001270202022401270100011402020224021402000127020202240127010001140202022401140300062701000614", | ||
"0x000b17100703000629010006290300012902020224012901000129020202240529020202240329020202240229020001290202022401290100012902020224022902000129020202240129010001290202022401290300062901000629", | ||
]; | ||
|
||
const encodedGlasses = inflateTraits(deflatedGlasses); | ||
expect(encodedGlasses).toStrictEqual(expectedTraits); | ||
}); | ||
}); |
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 @@ | ||
import { inflateRaw } from "pako"; | ||
import { decodeAbiParameters } from "viem"; | ||
import { DeflatedTraitsData, EncodedTrait } from "../types/artwork.js"; | ||
|
||
export const inflateTraits = (data: DeflatedTraitsData): EncodedTrait[] => { | ||
const [encodedTraits] = decodeAbiParameters( | ||
[{ type: "bytes[]" }], | ||
("0x" + | ||
Buffer.from(inflateRaw(Buffer.from(data.slice(2), "hex"))).toString( | ||
"hex" | ||
)) as `0x${string}` | ||
); | ||
|
||
return [...encodedTraits]; | ||
}; |
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,10 @@ | ||
import { decodeTrait } from "../artwork/decodeTrait.js"; | ||
import { inflateTraits } from "../artwork/inflateTraits.js"; | ||
|
||
const [data] = process.argv.slice(2); | ||
|
||
const encodedTraits = inflateTraits(data as `0x${string}`); | ||
|
||
const decodedTraits = encodedTraits.map((trait) => decodeTrait(trait, 32, 32)); | ||
|
||
console.log({ data, encodedTraits, decodedTraits }); |
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
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
Oops, something went wrong.