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

Key changes to CropXYZ function calls and events #395

Merged
21 changes: 21 additions & 0 deletions src/contextualizers/contextualizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ import ens0xdb203e93 from './test/transactions/ens-0xdb203e93.json';
import ens0xea1b4ab6 from './test/transactions/ens-0xea1b4ab6.json';
import ensRegistrar0xb14b4771 from './test/transactions/ensRegistrar-0xb14b4771.json';
import ensBulkRenew0x25add712 from './test/transactions/ensBulkRenew-0x25add712.json';
// CropXyz
import cropXyzPlotAction0x9436b659 from './test/transactions/cropXyzPlotAction-0x9436b659.json';
import cropXyzPlotAction0x9bb5a737 from './test/transactions/cropXyzPlotAction-0x9bb5a737.json';
import cropXyzPlotAction0x496c6309 from './test/transactions/cropXyzPlotAction-0x496c6309.json';

describe('ContextualizerService', () => {
describe('Detect transactions correctly', () => {
Expand Down Expand Up @@ -234,5 +238,22 @@ describe('ContextualizerService', () => {
);
expect(bulkRenew.context?.summaries?.en.title).toBe('ENS');
});

it('Should detect CropXYZ', () => {
const plotAction1 = contextualizer.contextualize(
cropXyzPlotAction0x9436b659 as unknown as Transaction,
);
expect(plotAction1.context?.summaries?.en.title).toBe('CropXYZ');

const plotAction2 = contextualizer.contextualize(
cropXyzPlotAction0x9bb5a737 as unknown as Transaction,
);
expect(plotAction2.context?.summaries?.en.title).toBe('CropXYZ');

const plotAction3 = contextualizer.contextualize(
cropXyzPlotAction0x496c6309 as unknown as Transaction,
);
expect(plotAction3.context?.summaries?.en.title).toBe('CropXYZ');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------- | -------- |
| PackActivationSource | [0xde1bc6e9164af5a48c45111b811c61f11ce58d91](https://www.onceupon.xyz/0xde1bc6e9164af5a48c45111b811c61f11ce58d91:8453) | Base |
| PackActivationDestination | [0x21170f8bd35d0afa8ad55719ce29d6489a8585db](https://www.onceupon.xyz/0x21170f8bd35d0afa8ad55719ce29d6489a8585db:4653) | Gold |
| PlotAction | [0xb45805566a842efb6329c11e092158f3e0eddaa2](https://www.onceupon.xyz/0xb45805566a842efb6329c11e092158f3e0eddaa2:4653) | Gold |
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const abi = [
{
inputs: [
{
internalType: 'address[]',
name: 'addressListing',
type: 'address[]',
},
{
internalType: 'uint256',
name: 'activationSourceNonce',
Expand All @@ -26,11 +31,6 @@ const abi = [
name: 'randomListingYield',
type: 'uint8[]',
},
{
internalType: 'address',
name: 'activator',
type: 'address',
},
{
internalType: 'uint8',
name: 'season',
Expand Down Expand Up @@ -70,6 +70,12 @@ const abi = [
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'address[]',
name: 'addressListing',
type: 'address[]',
},
{
indexed: false,
internalType: 'uint256[]',
Expand All @@ -94,10 +100,16 @@ const abi = [
name: 'admin',
type: 'address',
},
{
indexed: true,
internalType: 'bytes32',
name: 'sugarcaneId',
type: 'bytes32',
},
{
indexed: true,
internalType: 'address',
name: 'activator',
name: 'assetDestination',
type: 'address',
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ const abi = [
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'address[]',
name: 'addressListing',
type: 'address[]',
},
{
indexed: false,
internalType: 'bytes32',
Expand All @@ -27,7 +33,7 @@ const abi = [
type: 'uint256',
},
{
indexed: false,
indexed: true,
internalType: 'uint256',
name: 'sizeSpecificTokenId',
type: 'uint256',
Expand All @@ -50,12 +56,6 @@ const abi = [
name: 'tokenURI',
type: 'string',
},
{
indexed: true,
internalType: 'address',
name: 'activator',
type: 'address',
},
],
name: 'ActivatedStarterPackOnSource',
type: 'event',
Expand Down
188 changes: 188 additions & 0 deletions src/contextualizers/protocol/cropXyz/abis/PlotAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
const abi = [
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'player',
type: 'address',
},
{
indexed: true,
internalType: 'uint256',
name: 'plotId',
type: 'uint256',
},
{
indexed: true,
internalType: 'uint256',
name: 'stakedElement',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'newStakedElement',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint16',
name: 'harvestableAmount',
type: 'uint16',
},
{
indexed: false,
internalType: 'uint16',
name: 'actuallyProducedAmount',
type: 'uint16',
},
{
indexed: false,
internalType: 'uint24',
name: 'plotHarvests',
type: 'uint24',
},
],
name: 'HarvestedPlot',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'player',
type: 'address',
},
{
indexed: true,
internalType: 'uint256',
name: 'plotId',
type: 'uint256',
},
{
indexed: true,
internalType: 'uint256',
name: 'diedStakedElement',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'newStakedElement',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint16',
name: 'diedAmount',
type: 'uint16',
},
{
indexed: false,
internalType: 'uint24',
name: 'plotDeaths',
type: 'uint24',
},
],
name: 'ClearedDiedHarvest',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'player',
type: 'address',
},
{
indexed: true,
internalType: 'uint256',
name: 'plotId',
type: 'uint256',
},
{
indexed: true,
internalType: 'uint256',
name: 'clearedStakedElement',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'newStakedElement',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint16',
name: 'clearedAmount',
type: 'uint16',
},
{
indexed: false,
internalType: 'uint24',
name: 'plotClears',
type: 'uint24',
},
],
name: 'ClearedHarvest',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'player',
type: 'address',
},
{
indexed: true,
internalType: 'uint256',
name: 'plotId',
type: 'uint256',
},
{
indexed: true,
internalType: 'uint256',
name: 'stakedElement',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint16',
name: 'stakedAmount',
type: 'uint16',
},
{
indexed: false,
internalType: 'uint64',
name: 'timeStartStaked',
type: 'uint64',
},
{
indexed: false,
internalType: 'uint64',
name: 'timeReadyDelta',
type: 'uint64',
},
{
indexed: false,
internalType: 'uint64',
name: 'timeExpiredDelta',
type: 'uint64',
},
],
name: 'StakedCrop',
type: 'event',
},
] as const;

export default abi;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import packActivationDestinationAbi from './abis/PackActivationDestination';
import packActivationSourceAbi from './abis/PackActivationSource';
import plotActionAbi from './abis/PlotAction';

export const PACK_ACTIVATION_DESTINATION_CONTRACT =
'0x21170f8bd35d0afa8ad55719ce29d6489a8585db';
Expand All @@ -9,6 +10,9 @@ export const PLOT_ERC721_CONTRACT =
'0xe2f275b2a5c376fd10006b67a9be0cc3bd5488e8';
export const Z_GOLD_CONTRACT_ADDRESS =
'0x387d73bd8682dceb3327b940213d5de50ee2bba2';
export const PLOT_ACTION_CONTRACT_ADDRESS =
'0xb45805566a842efb6329c11e092158f3e0eddaa2';

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

describe('CropXYZ Destination', () => {
it('Should detect transaction', () => {
const isCropXYZDestination1 = detect(
goldDestination0x2b1c6528 as unknown as Transaction,
);
expect(isCropXYZDestination1).toBe(true);
});

describe('Should generate context', () => {
it('Should generate context for one tx', () => {
const transaction1 = generate(
goldDestination0x2b1c6528 as unknown as Transaction,
);
expect(transaction1.context?.summaries?.en.title).toBe('CropXYZ');
expect(contextSummary(transaction1.context)).toBe(
'0x9a37e57d177c5ff8817b55da36f2a2b3532cde3f RECEIVED plots 0xe2f275b2a5c376fd10006b67a9be0cc3bd5488e8 #4 and 0xe2f275b2a5c376fd10006b67a9be0cc3bd5488e8 #5 and 9 0xf4a785a80d91cadc149f778ee17d35cd008203f7 and 202816 0x387d73bd8682dceb3327b940213d5de50ee2bba2',
);
expect(containsBigInt(transaction1.context)).toBe(false);
});
});
});
Loading
Loading