Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contextualize gold #362

Merged
merged 10 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/contextualizers/protocol/gold/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Gold contract

| Contract | Address | Chain ID |
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------- | -------- |
| PackActivationSource | [0xde1bc6e9164af5a48c45111b811c61f11ce58d91](https://www.onceupon.xyz/0xde1bc6e9164af5a48c45111b811c61f11ce58d91:8453) | Base |
| PackActivationDestination | [0x21170f8bd35d0afa8ad55719ce29d6489a8585db](https://www.onceupon.xyz/0x21170f8bd35d0afa8ad55719ce29d6489a8585db:4653) | Gold |
231 changes: 231 additions & 0 deletions src/contextualizers/protocol/gold/abis/PackActivationDestination.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
const abi = [
{
inputs: [
{
internalType: 'uint256',
name: 'activationSourceNonce',
type: 'uint256',
},
{
internalType: 'string',
name: 'plotTypeNameEntered',
type: 'string',
},
{
internalType: 'string',
name: 'cropName',
type: 'string',
},
{
internalType: 'uint8[]',
name: 'randomListingGrowthRate',
type: 'uint8[]',
},
{
internalType: 'uint8[]',
name: 'randomListingYield',
type: 'uint8[]',
},
{
internalType: 'address',
name: 'activator',
type: 'address',
},
{
internalType: 'uint8',
name: 'season',
type: 'uint8',
},
{
internalType: 'uint8',
name: 'size',
type: 'uint8',
},
{
internalType: 'uint8',
name: 'tileArea',
type: 'uint8',
},
{
internalType: 'uint8',
name: 'fertilizer',
type: 'uint8',
},
{
internalType: 'uint8',
name: 'growthRateIndex',
type: 'uint8',
},
{
internalType: 'uint8',
name: 'yieldIndex',
type: 'uint8',
},
],
name: 'activateDestination',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'uint256[]',
name: 'plotIds',
type: 'uint256[]',
},
{
indexed: true,
internalType: 'uint256',
name: 'activationSourceNonce',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'activationDestinationNonce',
type: 'uint256',
},
{
indexed: false,
internalType: 'address',
name: 'admin',
type: 'address',
},
{
indexed: true,
internalType: 'address',
name: 'activator',
type: 'address',
},
{
indexed: false,
internalType: 'uint8',
name: 'season',
type: 'uint8',
},
{
indexed: false,
internalType: 'uint8',
name: 'size',
type: 'uint8',
},
{
indexed: false,
internalType: 'uint8',
name: 'tileArea',
type: 'uint8',
},
{
indexed: false,
internalType: 'uint8',
name: 'fertilizer',
type: 'uint8',
},
],
name: 'ActivatedStarterPackOnDestination',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'address',
name: 'minter',
type: 'address',
},
{
indexed: true,
internalType: 'uint256',
name: 'id',
type: 'uint256',
},
{
indexed: true,
internalType: 'address',
name: 'to',
type: 'address',
},
{
indexed: false,
internalType: 'uint8',
name: 'season',
type: 'uint8',
},
{
indexed: false,
internalType: 'string',
name: 'plotTypeName',
type: 'string',
},
{
indexed: true,
internalType: 'uint256',
name: 'plotTypeId',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint8',
name: 'width',
type: 'uint8',
},
{
indexed: false,
internalType: 'uint8',
name: 'height',
type: 'uint8',
},
{
indexed: false,
internalType: 'uint8',
name: 'tileArea',
type: 'uint8',
},
{
indexed: false,
internalType: 'uint8',
name: 'baseGrowthSpeed',
type: 'uint8',
},
{
indexed: false,
internalType: 'uint8',
name: 'baseYield',
type: 'uint8',
},
],
name: 'MintedPlotPackActivate',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'gameAddress',
type: 'address',
},
{
indexed: true,
internalType: 'address',
name: 'account',
type: 'address',
},
{
indexed: true,
internalType: 'uint256',
name: 'amount',
type: 'uint256',
},
],
name: 'GameMintedToken',
type: 'event',
},
] as const;

export default abi;
65 changes: 65 additions & 0 deletions src/contextualizers/protocol/gold/abis/PackActivationSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const abi = [
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'bytes32',
name: 'blockHash',
type: 'bytes32',
},
{
indexed: false,
internalType: 'uint256',
name: 'blockNumber',
type: 'uint256',
},
{
indexed: true,
internalType: 'uint256',
name: 'activationSourceNonce',
type: 'uint256',
},
{
indexed: true,
internalType: 'uint256',
name: 'tokenId',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'sizeSpecificTokenId',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'width',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'height',
type: 'uint256',
},
{
indexed: false,
internalType: 'string',
name: 'tokenURI',
type: 'string',
},
{
indexed: true,
internalType: 'address',
name: 'activator',
type: 'address',
},
],
name: 'ActivatedStarterPackOnSource',
type: 'event',
},
] as const;

export default abi;
14 changes: 14 additions & 0 deletions src/contextualizers/protocol/gold/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import packActivationDestinationAbi from './abis/PackActivationDestination';
import packActivationSourceAbi from './abis/PackActivationSource';

export const PACK_ACTIVATION_DESTINATION_CONTRACT =
'0x21170f8bd35d0afa8ad55719ce29d6489a8585db';
export const PACK_ACTIVATION_SOURCE_CONTRACT =
'0xde1bc6e9164af5a48c45111b811c61f11ce58d91';
export const PLOT_ERC721_CONTRACT =
'0xe2f275b2a5c376fd10006b67a9be0cc3bd5488e8';
export const Z_GOLD_CONTRACT_ADDRESS =
'0x387d73bd8682dceb3327b940213d5de50ee2bba2';

export const PACK_ACTIVATION_SOURCE_ABI = packActivationSourceAbi;
export const PACK_ACTIVATION_DESTINATION_ABI = packActivationDestinationAbi;
42 changes: 42 additions & 0 deletions src/contextualizers/protocol/gold/destination.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Transaction } from '../../../types';
import { detect, generate } from './destination';
import { containsBigInt, contextSummary } from '../../../helpers/utils';
import goldDestination0x85058886 from '../../test/transactions/goldDestination-0x85058886.json';
import goldDestination0x469f8c9c from '../../test/transactions/goldDestination-0x469f8c9c.json';

describe('Gold Destination', () => {
it('Should detect transaction', () => {
const isGoldDestination1 = detect(
goldDestination0x85058886 as unknown as Transaction,
);
expect(isGoldDestination1).toBe(true);

const isGoldDestination2 = detect(
goldDestination0x469f8c9c as unknown as Transaction,
);
expect(isGoldDestination2).toBe(true);
});

describe('Should generate context', () => {
it('Should generate context for one tx', () => {
const transaction1 = generate(
goldDestination0x85058886 as unknown as Transaction,
);
expect(transaction1.context?.summaries?.en.title).toBe('Gold');
expect(contextSummary(transaction1.context)).toBe(
'0xB374FDD2951A65e827Dab88f692a6819dc43c6D7 RECEIVED plots 0xe2f275b2a5c376fd10006b67a9be0cc3bd5488e8 #0 and 0xe2f275b2a5c376fd10006b67a9be0cc3bd5488e8 #1 and 81 0xc1e5e0dc7e94f9167ccf983ba26f7c21c83e0a33 and 912670 0x387d73bd8682dceb3327b940213d5de50ee2bba2',
);
expect(containsBigInt(transaction1.context)).toBe(false);
});
it('Should generate context for another tx', () => {
const transaction2 = generate(
goldDestination0x469f8c9c as unknown as Transaction,
);
expect(transaction2.context?.summaries?.en.title).toBe('Gold');
expect(contextSummary(transaction2.context)).toBe(
'0x18F33CEf45817C428d98C4E188A770191fDD4B79 RECEIVED plots 0xe2f275b2a5c376fd10006b67a9be0cc3bd5488e8 #2 and 0xe2f275b2a5c376fd10006b67a9be0cc3bd5488e8 #3 and 9 0xc1e5e0dc7e94f9167ccf983ba26f7c21c83e0a33 and 202816 0x387d73bd8682dceb3327b940213d5de50ee2bba2',
);
expect(containsBigInt(transaction2.context)).toBe(false);
});
});
});
Loading
Loading