Skip to content

Commit

Permalink
Add new contracts support
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemKolodko committed Nov 20, 2024
1 parent 323ccd5 commit b8bbb09
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ NODE_ENV=development
PORT=8085
DATABASE_URL=postgres://username:9999@localhost:5432/pump_fun_db

TOKEN_FACTORY_ADDRESS=0xB62780157f4f6da6419a4bFf8ec72663867042B5
INDEXER_INITIAL_BLOCK_NUMBER=65280179
TOKEN_FACTORY_ADDRESS=0xC256cb8099bF053a866c276F4a5416130358031c
INDEXER_INITIAL_BLOCK_NUMBER=65709108

# https://console.cloud.google.com/storage/browser/pump-fun-metadata
GOOGLE_CLOUD_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n..."
Expand Down
124 changes: 83 additions & 41 deletions src/abi/TokenFactory.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@
"name": "winner",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "competitionId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
Expand Down Expand Up @@ -235,6 +241,12 @@
"name": "creator",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "competitionId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
Expand Down Expand Up @@ -371,7 +383,7 @@
"name": "bondingCurve",
"outputs": [
{
"internalType": "contract BondingCurve",
"internalType": "contract BancorBondingCurve",
"name": "",
"type": "address"
}
Expand Down Expand Up @@ -444,7 +456,26 @@
"type": "address"
}
],
"name": "collateralByDay",
"name": "collateralById",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "competitionIds",
"outputs": [
{
"internalType": "uint256",
Expand Down Expand Up @@ -485,14 +516,8 @@
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "creationDate",
"inputs": [],
"name": "currentCompetitionId",
"outputs": [
{
"internalType": "uint256",
Expand Down Expand Up @@ -533,11 +558,11 @@
"inputs": [
{
"internalType": "uint256",
"name": "day",
"name": "competitionId",
"type": "uint256"
}
],
"name": "getWinnerByDay",
"name": "getWinnerByCompetitionId",
"outputs": [
{
"internalType": "address",
Expand All @@ -548,19 +573,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "maxFundingRateInterval",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
Expand Down Expand Up @@ -629,62 +641,92 @@
"inputs": [
{
"internalType": "uint256",
"name": "interval",
"name": "competitionId",
"type": "uint256"
}
],
"name": "setMaxFundingRateInterval",
"name": "setWinnerByCompetitionId",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "setWinner",
"name": "startNewCompetition",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "startOfCurrentDay",
"name": "tokenImplementation",
"outputs": [
{
"internalType": "uint256",
"internalType": "address",
"name": "",
"type": "uint256"
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "tokenImplementation",
"outputs": [
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "tokens",
"outputs": [
{
"internalType": "enum TokenFactory.TokenState",
"name": "",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "tokensByCompetitionId",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "tokens",
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "totalTokensByCompetitionId",
"outputs": [
{
"internalType": "enum TokenFactory.TokenState",
"internalType": "uint256",
"name": "",
"type": "uint8"
"type": "uint256"
}
],
"stateMutability": "view",
Expand Down Expand Up @@ -732,17 +774,17 @@
{
"inputs": [
{
"internalType": "address",
"internalType": "uint256",
"name": "",
"type": "address"
"type": "uint256"
}
],
"name": "winners",
"outputs": [
{
"internalType": "uint256",
"internalType": "address",
"name": "",
"type": "uint256"
"type": "address"
}
],
"stateMutability": "view",
Expand Down
4 changes: 4 additions & 0 deletions src/entities/token.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export class Token {
@Column({ type: 'json', nullable: true })
uriData: TokenMetadata | null;

@ApiProperty()
@Column({ type: 'integer' })
competitionId: number;

@ApiProperty()
@Column({ type: 'integer' })
timestamp: number;
Expand Down
4 changes: 4 additions & 0 deletions src/entities/token.winner.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class TokenWinner {
})
token: Token

@ApiProperty()
@Column({ type: 'decimal', default: 0 })
competitionId: string;

@ApiProperty()
@Column({ type: 'decimal', default: 0 })
timestamp: string;
Expand Down
14 changes: 9 additions & 5 deletions src/indexer/indexer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class IndexerService {
const blockNumber = Number(event.blockNumber)
const values = event.returnValues
const winnerAddress = (values['winner'] as string).toLowerCase()
const competitionId = String(values['competitionId'] as bigint)
const timestamp = String(values['timestamp'] as bigint)

if(winnerAddress === ZeroAddress) {
Expand All @@ -100,16 +101,17 @@ export class IndexerService {
const existedWinner = await transactionalEntityManager.findOne(TokenWinner, {
where: {
token: {
address: winnerAddress
address: winnerAddress,
},
competitionId,
timestamp
}
})

if(!existedWinner) {
const token = await this.appService.getTokenByAddress(winnerAddress, transactionalEntityManager)
if(!token) {
this.logger.error(`Winner token entry not found in database, winnerAddress=${winnerAddress} , exit`)
this.logger.error(`Failed to add winner: winner token not found in database, winnerAddress=${winnerAddress}, exit`)
process.exit(1)
}
await transactionalEntityManager.insert(TokenWinner, {
Expand All @@ -132,6 +134,7 @@ export class IndexerService {
const symbol = values['symbol'] as string
const uri = values['uri'] as string
const creatorAddress = (values['creator'] as string).toLowerCase()
const competitionId = Number(values['competitionId'] as bigint)
const timestamp = Number(values['timestamp'] as bigint)

let uriData = null
Expand Down Expand Up @@ -159,12 +162,13 @@ export class IndexerService {
blockNumber: Number(event.blockNumber),
name,
symbol,
competitionId,
timestamp,
user,
uri,
uriData,
});
this.logger.log(`Create token: address=${tokenAddress}, name=${name}, symbol=${symbol}, uri=${uri}, creator=${creatorAddress}, txnHash=${txnHash}`);
this.logger.log(`Create token: address=${tokenAddress}, name=${name}, symbol=${symbol}, uri=${uri}, creator=${creatorAddress}, competitionId=${competitionId}, txnHash=${txnHash}`);
}

private async processTradeEvent(type: TradeType, event: EventLog, transactionalEntityManager: EntityManager) {
Expand Down Expand Up @@ -296,14 +300,14 @@ export class IndexerService {

if(toBlock - fromBlock >= 1) {
const setWinnerEvents = await this.tokenFactoryContract.getPastEvents('allEvents', {
fromBlock, toBlock, topics: [ this.web3.utils.sha3('SetWinner(address,uint256)')],
fromBlock, toBlock, topics: [ this.web3.utils.sha3('SetWinner(address,uint256,uint256)')],
}) as EventLog[];

const tokenCreatedEvents = await this.tokenFactoryContract.getPastEvents('allEvents', {
fromBlock,
toBlock,
topics: [
this.web3.utils.sha3('TokenCreated(address,string,string,string,address,uint256)'),
this.web3.utils.sha3('TokenCreated(address,string,string,string,address,uint256,uint256)'),
],
}) as EventLog[];

Expand Down

0 comments on commit b8bbb09

Please sign in to comment.