Skip to content

Commit

Permalink
Merge pull request #25 from Once-Upon/feat/update-cryptopunks
Browse files Browse the repository at this point in the history
Update cryptopunks
  • Loading branch information
pcowgill authored Mar 4, 2024
2 parents 99be4f8 + 151ce7d commit aa54eab
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/blocks/ethereum/19362604_decoded.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/blocks/ethereum/19363120_decoded.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/blocks/ethereum/3846659_decoded.json

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions src/transformers/ethereum/assetTransfersCryptopunks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,93 @@ describe('transactionAssetTransfersCryptopunks', () => {
}
expect(cryptoPunksTransfers[0].type).toBe('erc721');
}

const cryptoPunksBlock1 = loadBlockFixture('ethereum', '19363120_decoded');
const cryptoPunksAssetResult1 =
transactionAssetTransfers(cryptoPunksBlock1);
const cryptoPunksResult1 = transform(cryptoPunksAssetResult1);
const cryptoPunksTx1 = cryptoPunksResult1.transactions.find(
(tx) =>
tx.hash ===
'0x61c6007a23dee8301b7f3e0546ac596087a8496900e0b5a6e1eace3fafc9905d',
);
expect(cryptoPunksTx1).toBeDefined();
if (cryptoPunksTx1) {
const cryptoPunksTransfers = cryptoPunksTx1.assetTransfers;
expect(cryptoPunksTransfers.length).toBe(1);
if ('tokenId' in cryptoPunksTransfers[0]) {
expect(cryptoPunksTransfers[0].tokenId).toBe('8379');
expect(cryptoPunksTransfers[0].from).toBe(
'0xbb26a6da4d918682f58cc91bd3fb251dd28549d2',
);
expect(cryptoPunksTransfers[0].to).toBe(
'0x347e9f9ddd45bf8a77db9aaa8f06d671698f8dc2',
);
}
expect(cryptoPunksTransfers[0].type).toBe('erc721');
}

const cryptoPunksBlock2 = loadBlockFixture('ethereum', '19362604_decoded');
const cryptoPunksAssetResult2 =
transactionAssetTransfers(cryptoPunksBlock2);
const cryptoPunksResult2 = transform(cryptoPunksAssetResult2);
const cryptoPunksTx2 = cryptoPunksResult2.transactions.find(
(tx) =>
tx.hash ===
'0x9fbc06d3025c257a5e5d1f3c4c320fbfd18bdb43083e25f5d5b318e4b1300f15',
);
expect(cryptoPunksTx2).toBeDefined();
if (cryptoPunksTx2) {
const cryptoPunksTransfers = cryptoPunksTx2.assetTransfers;
expect(cryptoPunksTransfers.length).toBe(2);
if ('tokenId' in cryptoPunksTransfers[0]) {
expect(cryptoPunksTransfers[0].tokenId).toBe('1848');
expect(cryptoPunksTransfers[0].from).toBe(
'0x1919db36ca2fa2e15f9000fd9cdc2edcf863e685',
);
expect(cryptoPunksTransfers[0].to).toBe(
'0x0000000000000000000000000000000000000000',
);
}
expect(cryptoPunksTransfers[0].type).toBe('erc721');

if ('tokenId' in cryptoPunksTransfers[1]) {
expect(cryptoPunksTransfers[1].tokenId).toBe('1848');
expect(cryptoPunksTransfers[1].from).toBe(
'0xb7f7f6c52f2e2fdb1963eab30438024864c313f6',
);
expect(cryptoPunksTransfers[1].to).toBe(
'0x1919db36ca2fa2e15f9000fd9cdc2edcf863e685',
);
}
expect(cryptoPunksTransfers[1].type).toBe('erc721');
}
});

it('should return asset transfers for CryptoPunks assign transactions', () => {
const cryptoPunksBlock1 = loadBlockFixture('ethereum', '3846659_decoded');
const cryptoPunksAssetResult1 =
transactionAssetTransfers(cryptoPunksBlock1);
const cryptoPunksResult1 = transform(cryptoPunksAssetResult1);
const cryptoPunksTx1 = cryptoPunksResult1.transactions.find(
(tx) =>
tx.hash ===
'0xd7eecc44abcea1a4c9dbd7d7749595635f5dcf8d1795beef52ca36356be6201c',
);
expect(cryptoPunksTx1).toBeDefined();
if (cryptoPunksTx1) {
const cryptoPunksTransfers = cryptoPunksTx1.assetTransfers;
expect(cryptoPunksTransfers.length).toBe(1);
if ('tokenId' in cryptoPunksTransfers[0]) {
expect(cryptoPunksTransfers[0].tokenId).toBe('5350');
expect(cryptoPunksTransfers[0].from).toBe(
'0x0000000000000000000000000000000000000000',
);
expect(cryptoPunksTransfers[0].to).toBe(
'0x5b098b00621eda6a96b7a476220661ad265f083f',
);
}
expect(cryptoPunksTransfers[0].type).toBe('erc721');
}
});
});
37 changes: 27 additions & 10 deletions src/transformers/ethereum/assetTransfersCryptopunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
type RawBlock,
type RawTransaction,
} from '../../types';
import { CRYPTO_PUNKS_ADDRESSES } from '../../helpers/constants';
import {
CRYPTO_PUNKS_ADDRESSES,
KNOWN_ADDRESSES,
} from '../../helpers/constants';

const TRANSFER_SIGNATURES = {
// event PunkTransfer(address indexed from, address indexed to, uint256 punkIndex)
Expand All @@ -14,6 +17,9 @@ const TRANSFER_SIGNATURES = {
// event PunkBought(uint indexed punkIndex, uint value, address indexed fromAddress, address indexed toAddress)
CRYPTO_PUNKS_ERC721_BUY:
'0x58e5d5a525e3b40bc15abaa38b5882678db1ee68befd2f60bafe3a7fd06db9e3',
// Assign (index_topic_1 address to, uint256 punkIndex)
CRYPTO_PUNKS_ERC721_ASSIGN:
'0x8a0e37b73a0d9c82e205d4d1a3ff3d0b57ce5f4d7bccf6bac03336dc101cb7ba',
};

function updateTokenTransfers(tx: RawTransaction) {
Expand Down Expand Up @@ -45,29 +51,40 @@ function updateTokenTransfers(tx: RawTransaction) {
type: AssetType.ERC721,
});
break;
case TRANSFER_SIGNATURES.CRYPTO_PUNKS_ERC721_ASSIGN:
cryptopunksTransfers.push({
asset: log.address,
from: KNOWN_ADDRESSES.NULL,
to: decodeEVMAddress(log.topics[1]),
tokenId: BigInt(log.data).toString(),
type: AssetType.ERC721,
});
break;
default:
break;
}
}

// filter old asset transfers from previous asset transfers
const nonOldAssetTransfers = tx.assetTransfers.filter(
(assetTransfer) =>
assetTransfer.type !== AssetType.ETH &&
!CRYPTO_PUNKS_ADDRESSES.includes(assetTransfer.asset),
);
const nonOldAssetTransfers = tx.assetTransfers
? tx.assetTransfers.filter(
(assetTransfer) =>
assetTransfer.type !== AssetType.ETH &&
!CRYPTO_PUNKS_ADDRESSES.includes(assetTransfer.asset),
)
: [];
const assetTransfers = [...nonOldAssetTransfers, ...cryptopunksTransfers];

return assetTransfers;
}

export function transform(block: RawBlock): RawBlock {
block.transactions = block.transactions.map((tx) => {
const hasCryptopunksTransfer = tx.assetTransfers?.some(
(assetTransfer) =>
assetTransfer.type !== AssetType.ETH &&
CRYPTO_PUNKS_ADDRESSES.includes(assetTransfer.asset),
const logs = tx.receipt.logs;
const hasCryptopunksTransfer = logs?.some((log) =>
CRYPTO_PUNKS_ADDRESSES.includes(log.address),
);

if (hasCryptopunksTransfer) {
tx.assetTransfers = updateTokenTransfers(tx);
}
Expand Down

0 comments on commit aa54eab

Please sign in to comment.