-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
6e8e761
commit 58b50b9
Showing
4 changed files
with
354 additions
and
1 deletion.
There are no files selected for viewing
188 changes: 188 additions & 0 deletions
188
src/contextualizers/protocol/cropXYZ/abis/PlotAction.ts
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,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; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { | ||
Transaction, | ||
EventLogTopics, | ||
GoldContextActionEnum, | ||
} from '../../../types'; | ||
import { PLOT_ACTION_CONTRACT_ADDRESS, PLOT_ACTION_ABI } from './constants'; | ||
import { decodeLog } from '../../../helpers/utils'; | ||
|
||
export function contextualize(transaction: Transaction): Transaction { | ||
const isPackActivationSource = detect(transaction); | ||
if (!isPackActivationSource) return transaction; | ||
|
||
const result = generate(transaction); | ||
return result; | ||
} | ||
|
||
export function detect(transaction: Transaction): boolean { | ||
/** | ||
* There is a degree of overlap between the 'detect' and 'generateContext' functions, | ||
* and while this might seem redundant, maintaining the 'detect' function aligns with | ||
* established patterns in our other modules. This consistency is beneficial, | ||
* and it also serves to decouple the logic, thereby simplifying the testing process | ||
*/ | ||
// check logs | ||
if (!transaction.logs) return false; | ||
|
||
for (const log of transaction.logs) { | ||
if (log.address !== PLOT_ACTION_CONTRACT_ADDRESS) continue; | ||
|
||
const decoded = decodeLog(PLOT_ACTION_ABI, log.data, [ | ||
log.topic0, | ||
log.topic1, | ||
log.topic2, | ||
log.topic3, | ||
] as EventLogTopics); | ||
|
||
if ( | ||
decoded && | ||
(decoded.eventName === 'HarvestedPlot' || | ||
decoded.eventName === 'ClearedDiedHarvest' || | ||
decoded.eventName === 'ClearedHarvest' || | ||
decoded.eventName === 'StakedCrop') | ||
) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export function generate(transaction: Transaction): Transaction { | ||
if (!transaction.logs || !transaction.chainId) return transaction; | ||
|
||
// decode ActivatedStarterPackOnSource event | ||
let decoded; | ||
for (const log of transaction.logs) { | ||
if (log.address !== PLOT_ACTION_CONTRACT_ADDRESS) continue; | ||
|
||
decoded = decodeLog(PLOT_ACTION_ABI, log.data, [ | ||
log.topic0, | ||
log.topic1, | ||
log.topic2, | ||
log.topic3, | ||
] as EventLogTopics); | ||
|
||
if (decoded && decoded.eventName === 'HarvestedPlot') { | ||
const player = decoded.args['player']; | ||
const plotId = decoded.args['plotId']; | ||
transaction.context = { | ||
summaries: { | ||
category: 'PROTOCOL_1', | ||
en: { | ||
title: `Gold`, | ||
default: '[[player]][[harvested]]plots[[plotId]]', | ||
}, | ||
}, | ||
variables: { | ||
player: { | ||
type: 'address', | ||
value: player, | ||
}, | ||
plotId: { | ||
type: 'number', | ||
value: plotId, | ||
}, | ||
harvested: { | ||
type: 'contextAction', | ||
value: GoldContextActionEnum.HARVESTED_PLOT, | ||
}, | ||
}, | ||
}; | ||
return transaction; | ||
} | ||
|
||
if (decoded && decoded.eventName === 'ClearedHarvest') { | ||
const player = decoded.args['player']; | ||
const plotId = decoded.args['plotId']; | ||
transaction.context = { | ||
summaries: { | ||
category: 'PROTOCOL_1', | ||
en: { | ||
title: `Gold`, | ||
default: '[[player]][[clearedHarvest]]plots[[plotId]]', | ||
}, | ||
}, | ||
variables: { | ||
player: { | ||
type: 'address', | ||
value: player, | ||
}, | ||
plotId: { | ||
type: 'number', | ||
value: plotId, | ||
}, | ||
clearedHarvest: { | ||
type: 'contextAction', | ||
value: GoldContextActionEnum.CLEARED_HARVEST, | ||
}, | ||
}, | ||
}; | ||
return transaction; | ||
} | ||
|
||
if (decoded && decoded.eventName === 'StakedCrop') { | ||
const player = decoded.args['player']; | ||
const plotId = decoded.args['plotId']; | ||
transaction.context = { | ||
summaries: { | ||
category: 'PROTOCOL_1', | ||
en: { | ||
title: `Gold`, | ||
default: '[[player]][[stakedCrop]]plots[[plotId]]', | ||
}, | ||
}, | ||
variables: { | ||
player: { | ||
type: 'address', | ||
value: player, | ||
}, | ||
plotId: { | ||
type: 'number', | ||
value: plotId, | ||
}, | ||
stakedCrop: { | ||
type: 'contextAction', | ||
value: GoldContextActionEnum.STAKED_CROP, | ||
}, | ||
}, | ||
}; | ||
return transaction; | ||
} | ||
} | ||
|
||
return transaction; | ||
} |
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