It’s been quite some time since the last substack! A lot of things were happening on my side, I apologise for the long hiatus.
Where were we again?
So last time we managed to complete the ERC-20 part of our Shibuya.xyz dashboard, so as promised I will take on the ERC-1155 part of Shibuya.
Ethereum token standards
First things first, it is quite important for anyone having reached this article to be fully familiarised with the the Ethereum token standards, and especially on the meaning of fungibility.
If you are not so sure on what you just read, you should take take a quick detour too refresh your fundamentals:
Shibuya token structure
As explained in Chapter 6, Shibuya uses both ERC-20 tokens and ERC-1155.
The ERC-1155 non-fungible tokens are called White Rabbit Producer Passes or $WRPP. Here are the overarching mechanics and behind usages the $WRPP:
At every iteration, a fixed supply of $WRPP is created (for Chapter 1 - 5,000 $WRPP were created, and for Chapter 2 - 6,000 $WRPP were created).
Even though the $WRPP are under the same contract, they have a different id depending on the chapter for which they were issued.
The $WRPP created at each iteration are sold off through a fundraising mechanism to raise funds for the team to operate.
The holder of the $WRPP is entitled to stake the $WRPP onto a master contract, and to cast a vote in the direction that he wishes the movie to proceed, hence why the token is called a producer pass.
At the end of the voting period, the staker can unstake his staked $ WRPP from the master contract, and receive a pre determined quantity of $WRAB.
Before or after the staking, the $WRPP holder can chose to sell the $WRPP back onto the Opensea secondary market.
$WPPP queries
Chapter 1 $WRPP sale
The first question that we want to be answered is on the sale of $WRPP:
How many $WRPP have been sold?
How fast were they sold?
Quick learn: When it comes to ERC-1155 Dune V2 already has the abstraction ready: erc1155_ethereum.evt_TransferSingle
.
Cool, so let’s get a first sniff at that abstraction.
SELECT
evt_block_time,
`from`,
`to`,
id,
value
FROM erc1155_ethereum.evt_TransferSingle
WHERE contract_address = '0x97ed92e744c10fdd5d403a756239c4069e415e79'
AND `from` = '0x0000000000000000000000000000000000000000'
AND id = 1
What did I do?
First of all I selected only the data I needed, in this case: the timestamp, the sending and beneficiary address, the id, and the value of the transaction.
Quick learn: The biggest difference between ERC-721 and ERC-1155 is batch transfer, while ERC-721 is built for one to one transfer like JPEG trading, ERC-1155 is better suited for batch transfers like concert tickets.
This means that values like id and value (quantity) can be standardised across all ERC-1155. And in our case id is used to point to the Chapter number of the $WRPP and value refers to the number of ERC-1155 transferred in the transaction.
The contract address is the address of the White Rabbit Producer pass contract, and I filtered the transactions to show only mint transactions( transactions from '0x0000000000000000000000000000000000000000') and that have id 1 (Chapter 1 $WRPP).
While this data is nice, let’s make it more presentable:
SELECT
a.time,
(a.cumulative_passes_minted/5000) AS perc_passes_minted,
(1-(a.cumulative_passes_minted/5000)) AS perc_passes_not_yet_minted
FROM
(
SELECT
evt_block_time AS time,
SUM(value) OVER (ORDER BY evt_block_time ASC) AS cumulative_passes_minted
FROM erc1155_ethereum.evt_TransferSingle
WHERE contract_address = '0x97ed92e744c10fdd5d403a756239c4069e415e79'
AND `from` = '0x0000000000000000000000000000000000000000'
AND id = 1
) a
With a nice chart:
Quick learn:
This code SUM(value) OVER (ORDER BY evt_block_time ASC)
, is what is called a partition window, it conducts as small internal operation based on defined parameters. In this particular case, I am using it co calculate cumulative $WRPP minted, by calculating the sums of all rows below a specific date, when the rows are arranged by evt_block_time from earliest to last. It is a neat little trick to calculate cumulative sums that does not consume a lot of computing or brain power.
Chapter 2 $WRPP sale
Now, can we copy paste that for Chapter 2?
SELECT
a.time,
(a.cumulative_passes_minted/5000) AS perc_passes_minted,
(1-(a.cumulative_passes_minted/5000)) AS perc_passes_not_yet_minted
FROM
(
SELECT
evt_block_time AS time,
SUM(value) OVER (ORDER BY evt_block_time ASC) AS cumulative_passes_minted
FROM erc1155_ethereum.evt_TransferSingle
WHERE contract_address = '0x97ed92e744c10fdd5d403a756239c4069e415e79'
AND `from` = '0x0000000000000000000000000000000000000000'
AND id = 2 -- 2 Refers to Chapter 2
) a
Let’s run the above and switch id from 1 to 2:
Hmm there should be more than 1 line… Let’s unpack that:
SELECT *
FROM erc1155_ethereum.evt_TransferSingle
WHERE contract_address = '0x97ed92e744c10fdd5d403a756239c4069e415e79'
AND `from` = '0x0000000000000000000000000000000000000000'
AND id = 2
As we can see from the above, 6,000 Chapter 2 passes were minted from '0x0000000000000000000000000000000000000000' and sent to a second address, and it it seems that it was this address that was minting the passes to the end users.
So let’s try to swap the `from` to the above address.
SELECT
a.time,
(a.cumulative_passes_minted/6000) AS perc_passes_minted,
(1-(a.cumulative_passes_minted/6000)) AS perc_passes_not_yet_minted
FROM
(
SELECT
evt_block_time AS time,
SUM(value) OVER (ORDER BY evt_block_time ASC) AS cumulative_passes_minted
FROM erc1155_ethereum.evt_TransferSingle
WHERE contract_address = '0x97ed92e744c10fdd5d403a756239c4069e415e79'
AND `from` = '0x493ec74f40788c454ced05f551c8a993207e71b8'
AND id = 2 -- Refers to Chapter 2
) a
And it works! As we can see for Chapter 2, we did not get a complete sell out as we got in Chapter 1, only 55.95% of the total supply was sold (bear market things).
Takeout
We managed to dip out toes into ERC-1155 which after a little practice are no different from ERC-20 in terms of manipulation.
We had our first experience with partition windows, and managed to get some cool visualisations for our dashboard.
Let’s keep rock and rolling!