-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: add transaction stats entity [SF-1135] #96
Conversation
WalkthroughThe recent changes introduce new GraphQL types, Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- schema.graphql (1 hunks)
- src/helper/initializer.ts (2 hunks)
- src/mappings/lending-market.ts (2 hunks)
Additional context used
Biome
src/mappings/lending-market.ts
[error] 1-1: Do not shadow the global "BigInt" property. (lint/suspicious/noShadowRestrictedNames)
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
src/helper/initializer.ts
[error] 4-4: Do not shadow the global "BigInt" property. (lint/suspicious/noShadowRestrictedNames)
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
Additional comments not posted (2)
schema.graphql (1)
160-163
: LGTM! TheTransactionStatsContainer
type is well-defined with appropriate linking toTransactionStats
.src/mappings/lending-market.ts (1)
217-222
: Consider verifying the necessity ofupdateTransactionStats
in other event handlers to maintain consistency across the application.
# TODO: add for APR | ||
# TOOD: add for vol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct the spelling of "TODO" and provide more actionable details.
- # TOOD: add for vol
+ # TODO: Add functionality for calculating volume.
Also applies to: 166-166
Committable suggestion was skipped due to low confidence.
export function updateTransactionStats( | ||
currency: Bytes, | ||
maturity: BigInt, | ||
currentTimestamp: BigInt | ||
): void { | ||
const currentCandleStickId = getTransactionCandleStickEntityId( | ||
currency, | ||
maturity, | ||
BigInt.fromI32(86400), // 1 day interval | ||
currentTimestamp.div(BigInt.fromI32(86400)) | ||
); | ||
const currentCandleStick = | ||
TransactionCandleStick.load(currentCandleStickId); | ||
|
||
if (currentCandleStick) { | ||
const previousTimestamp = currentTimestamp.minus(BigInt.fromI32(86400)); | ||
const previousCandleStickId = getTransactionCandleStickEntityId( | ||
currency, | ||
maturity, | ||
BigInt.fromI32(86400), // 1 day interval | ||
previousTimestamp.div(BigInt.fromI32(86400)) | ||
); | ||
const previousCandleStick = TransactionCandleStick.load( | ||
previousCandleStickId | ||
); | ||
|
||
if (previousCandleStick) { | ||
const currentPrice = currentCandleStick.close; | ||
const previousPrice = previousCandleStick.close; | ||
|
||
const priceChange = currentPrice.minus(previousPrice); | ||
const percentageChange = priceChange | ||
.times(BigInt.fromI32(10000)) | ||
.div(previousPrice); | ||
|
||
const containerId = 'CONTAINER'; | ||
let container = TransactionStatsContainer.load(containerId); | ||
|
||
if (!container) { | ||
container = new TransactionStatsContainer(containerId); | ||
} | ||
|
||
const statsId = currency.toHexString() + '-' + maturity.toString(); | ||
let stats = TransactionStats.load(statsId); | ||
|
||
if (!stats) { | ||
stats = new TransactionStats(statsId); | ||
stats.currency = currency; | ||
stats.maturity = maturity; | ||
stats.container = container.id; | ||
stats.save(); | ||
} | ||
|
||
stats.priceChange = priceChange; | ||
stats.percentageChange = percentageChange.toBigDecimal(); | ||
stats.save(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a dynamic approach for generating containerId
to handle multiple containers effectively.
- const containerId = 'CONTAINER';
+ const containerId = generateContainerId(currency, maturity); // Implement this function to generate unique IDs based on currency and maturity.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export function updateTransactionStats( | |
currency: Bytes, | |
maturity: BigInt, | |
currentTimestamp: BigInt | |
): void { | |
const currentCandleStickId = getTransactionCandleStickEntityId( | |
currency, | |
maturity, | |
BigInt.fromI32(86400), // 1 day interval | |
currentTimestamp.div(BigInt.fromI32(86400)) | |
); | |
const currentCandleStick = | |
TransactionCandleStick.load(currentCandleStickId); | |
if (currentCandleStick) { | |
const previousTimestamp = currentTimestamp.minus(BigInt.fromI32(86400)); | |
const previousCandleStickId = getTransactionCandleStickEntityId( | |
currency, | |
maturity, | |
BigInt.fromI32(86400), // 1 day interval | |
previousTimestamp.div(BigInt.fromI32(86400)) | |
); | |
const previousCandleStick = TransactionCandleStick.load( | |
previousCandleStickId | |
); | |
if (previousCandleStick) { | |
const currentPrice = currentCandleStick.close; | |
const previousPrice = previousCandleStick.close; | |
const priceChange = currentPrice.minus(previousPrice); | |
const percentageChange = priceChange | |
.times(BigInt.fromI32(10000)) | |
.div(previousPrice); | |
const containerId = 'CONTAINER'; | |
let container = TransactionStatsContainer.load(containerId); | |
if (!container) { | |
container = new TransactionStatsContainer(containerId); | |
} | |
const statsId = currency.toHexString() + '-' + maturity.toString(); | |
let stats = TransactionStats.load(statsId); | |
if (!stats) { | |
stats = new TransactionStats(statsId); | |
stats.currency = currency; | |
stats.maturity = maturity; | |
stats.container = container.id; | |
stats.save(); | |
} | |
stats.priceChange = priceChange; | |
stats.percentageChange = percentageChange.toBigDecimal(); | |
stats.save(); | |
} | |
} | |
} | |
export function updateTransactionStats( | |
currency: Bytes, | |
maturity: BigInt, | |
currentTimestamp: BigInt | |
): void { | |
const currentCandleStickId = getTransactionCandleStickEntityId( | |
currency, | |
maturity, | |
BigInt.fromI32(86400), // 1 day interval | |
currentTimestamp.div(BigInt.fromI32(86400)) | |
); | |
const currentCandleStick = | |
TransactionCandleStick.load(currentCandleStickId); | |
if (currentCandleStick) { | |
const previousTimestamp = currentTimestamp.minus(BigInt.fromI32(86400)); | |
const previousCandleStickId = getTransactionCandleStickEntityId( | |
currency, | |
maturity, | |
BigInt.fromI32(86400), // 1 day interval | |
previousTimestamp.div(BigInt.fromI32(86400)) | |
); | |
const previousCandleStick = TransactionCandleStick.load( | |
previousCandleStickId | |
); | |
if (previousCandleStick) { | |
const currentPrice = currentCandleStick.close; | |
const previousPrice = previousCandleStick.close; | |
const priceChange = currentPrice.minus(previousPrice); | |
const percentageChange = priceChange | |
.times(BigInt.fromI32(10000)) | |
.div(previousPrice); | |
const containerId = generateContainerId(currency, maturity); // Implement this function to generate unique IDs based on currency and maturity. | |
let container = TransactionStatsContainer.load(containerId); | |
if (!container) { | |
container = new TransactionStatsContainer(containerId); | |
} | |
const statsId = currency.toHexString() + '-' + maturity.toString(); | |
let stats = TransactionStats.load(statsId); | |
if (!stats) { | |
stats = new TransactionStats(statsId); | |
stats.currency = currency; | |
stats.maturity = maturity; | |
stats.container = container.id; | |
stats.save(); | |
} | |
stats.priceChange = priceChange; | |
stats.percentageChange = percentageChange.toBigDecimal(); | |
stats.save(); | |
} | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
No description provided.