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

Refacto launchpad #451

Merged
merged 14 commits into from
Feb 2, 2025
11 changes: 5 additions & 6 deletions apps/nestjs-indexer/src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export default {
DECIMALS: 18,
STARTING_BLOCK: 140_000,
STARTING_BLOCK: 450_000,
STARTING_BLOCK_UNRUG: 615_556,
STARTING_BLOCK_MAINNET: 615_556,
contracts: {
mainnet: {
FACTORY_ADDRESS:
Expand All @@ -10,12 +11,10 @@ export default {
'0x01a46467a9246f45c8c340f1f155266a26a71c07bd55d36e8d1c7d0d438a2dbc',
},
sepolia: {
// LAUNCHPAD_ADDRESS:"0x525d47343caa4c56cd28eeeff7d503f1b80872c5a7f4a9f8ac8130de3513f70",

// LAUNCHPAD_ADDRESS:"0x6fbcf2a0df5716d83d9653985f9c9bde6fb73130f0804e18bb18ef6f6ae7ad2",
// LAUNCHPAD_ADDRESS:"0x6579503122e7564117f2192d6a66ec81b51dfd551b39a4fa26046044cd39a35",
LAUNCHPAD_ADDRESS:
'0x4cefb7ab4c3fda72df52f288e141ff1dc6956a497949bf7b0031f012f3d3afc',
// LAUNCHPAD_ADDRESS:
// '0x4cefb7ab4c3fda72df52f288e141ff1dc6956a497949bf7b0031f012f3d3afc',
LAUNCHPAD_ADDRESS:"0x4a5d414ec6085ef5d3779b6e72015076b1a1ecdb6065fe1123d794ff41aea4d",
NAMESERVICE_ADDRESS:
'0x15dcd3c28c07846fa98d3a40d29446de21b5e6cd8d49a43773da0f237d5ea7f',
ESCROW_DEPOSIT_ADDRESS:
Expand Down
206 changes: 105 additions & 101 deletions apps/nestjs-indexer/src/indexer/buy-token.indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,106 +54,110 @@ export class BuyTokenIndexer {
event: starknet.IEvent,
transaction: starknet.ITransaction,
) {
const {
blockNumber,
blockHash: blockHashFelt,
timestamp: blockTimestamp,
} = header;

const blockHash = validateAndParseAddress(
`0x${FieldElement.toBigInt(blockHashFelt).toString(16)}`,
) as ContractAddress;

const transactionHashFelt = transaction.meta.hash;
const transactionHash = validateAndParseAddress(
`0x${FieldElement.toBigInt(transactionHashFelt).toString(16)}`,
) as ContractAddress;

const transferId = `${transactionHash}_${event.index}`;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, callerFelt, tokenAddressFelt] = event.keys;

const ownerAddress = validateAndParseAddress(
`0x${FieldElement.toBigInt(callerFelt).toString(16)}`,
) as ContractAddress;

const tokenAddress = validateAndParseAddress(
`0x${FieldElement.toBigInt(tokenAddressFelt).toString(16)}`,
) as ContractAddress;

const [
amountLow,
amountHigh,
priceLow,
priceHigh,
protocolFeeLow,
protocolFeeHigh,
lastPriceLow,
lastPriceHigh,
timestampFelt,
quoteAmountLow,
quoteAmountHigh,
] = event.data;

const amountRaw = uint256.uint256ToBN({
low: FieldElement.toBigInt(amountLow),
high: FieldElement.toBigInt(amountHigh),
});
const amount = formatUnits(amountRaw, constants.DECIMALS).toString();

const priceRaw = uint256.uint256ToBN({
low: FieldElement.toBigInt(priceLow),
high: FieldElement.toBigInt(priceHigh),
});
const price = formatUnits(priceRaw, constants.DECIMALS);

const protocolFeeRaw = uint256.uint256ToBN({
low: FieldElement.toBigInt(protocolFeeLow),
high: FieldElement.toBigInt(protocolFeeHigh),
});
const protocolFee = formatUnits(
protocolFeeRaw,
constants.DECIMALS,
).toString();

const lastPriceRaw = uint256.uint256ToBN({
low: FieldElement.toBigInt(lastPriceLow),
high: FieldElement.toBigInt(lastPriceHigh),
});
const lastPrice = formatUnits(lastPriceRaw, constants.DECIMALS).toString();

const quoteAmountRaw = uint256.uint256ToBN({
low: FieldElement.toBigInt(quoteAmountLow),
high: FieldElement.toBigInt(quoteAmountHigh),
});
const quoteAmount = formatUnits(
quoteAmountRaw,
constants.DECIMALS,
).toString();

const timestamp = new Date(
Number(FieldElement.toBigInt(timestampFelt)) * 1000,
);

const data = {
transferId,
network: 'starknet-sepolia',
transactionHash,
blockNumber: Number(blockNumber),
blockHash,
blockTimestamp: new Date(Number(blockTimestamp.seconds) * 1000),
ownerAddress,
memecoinAddress: tokenAddress,
amount: Number(amount),
price,
protocolFee,
lastPrice,
quoteAmount,
timestamp,
transactionType: 'buy',
};

await this.buyTokenService.create(data);
try {
const {
blockNumber,
blockHash: blockHashFelt,
timestamp: blockTimestamp,
} = header;

const blockHash = validateAndParseAddress(
`0x${FieldElement.toBigInt(blockHashFelt).toString(16)}`,
) as ContractAddress;

const transactionHashFelt = transaction.meta.hash;
const transactionHash = validateAndParseAddress(
`0x${FieldElement.toBigInt(transactionHashFelt).toString(16)}`,
) as ContractAddress;

const transferId = `${transactionHash}_${event.index}`;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, callerFelt, tokenAddressFelt] = event.keys;

const ownerAddress = validateAndParseAddress(
`0x${FieldElement.toBigInt(callerFelt).toString(16)}`,
) as ContractAddress;

const tokenAddress = validateAndParseAddress(
`0x${FieldElement.toBigInt(tokenAddressFelt).toString(16)}`,
) as ContractAddress;

const [
amountLow,
amountHigh,
priceLow,
priceHigh,
protocolFeeLow,
protocolFeeHigh,
lastPriceLow,
lastPriceHigh,
timestampFelt,
quoteAmountLow,
quoteAmountHigh,
] = event.data;

const amountRaw = uint256.uint256ToBN({
low: FieldElement.toBigInt(amountLow),
high: FieldElement.toBigInt(amountHigh),
});
const amount = formatUnits(amountRaw, constants.DECIMALS).toString();

const priceRaw = uint256.uint256ToBN({
low: FieldElement.toBigInt(priceLow),
high: FieldElement.toBigInt(priceHigh),
});
const price = formatUnits(priceRaw, constants.DECIMALS);

const protocolFeeRaw = uint256.uint256ToBN({
low: FieldElement.toBigInt(protocolFeeLow),
high: FieldElement.toBigInt(protocolFeeHigh),
});
const protocolFee = formatUnits(
protocolFeeRaw,
constants.DECIMALS,
).toString();

const lastPriceRaw = uint256.uint256ToBN({
low: FieldElement.toBigInt(lastPriceLow),
high: FieldElement.toBigInt(lastPriceHigh),
});
const lastPrice = formatUnits(lastPriceRaw, constants.DECIMALS).toString();

const quoteAmountRaw = uint256.uint256ToBN({
low: FieldElement.toBigInt(quoteAmountLow),
high: FieldElement.toBigInt(quoteAmountHigh),
});
const quoteAmount = formatUnits(
quoteAmountRaw,
constants.DECIMALS,
).toString();

const timestamp = new Date(
Number(FieldElement.toBigInt(timestampFelt)) * 1000,
);

const data = {
transferId,
network: 'starknet-sepolia',
transactionHash,
blockNumber: Number(blockNumber),
blockHash,
blockTimestamp: new Date(Number(blockTimestamp.seconds) * 1000),
ownerAddress,
memecoinAddress: tokenAddress,
amount: Number(amount),
price,
protocolFee,
lastPrice,
quoteAmount,
timestamp,
transactionType: 'buy',
};

await this.buyTokenService.create(data);
} catch (error) {
console.log("Error BuyTokenIndexer", error)
}
}
}
Loading
Loading