-
Notifications
You must be signed in to change notification settings - Fork 36
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
Filter and Sorting ignores scale
in reward
object
#117
Comments
I think the Our database is our source of truth, and we should strive to:
I would propose changing the
However, given our dependency on the DEGEN team and our release date, I think our priorities are to implement a stable release, and clean up minor technical debt later. Thus, I think @jordaniza 's solution of adding the |
This makes sense, we can add fairly cleanly to our own API without affecting DEGEN if this is some sort of stored procedure (I'm assuming Mongo has these). Definitely a pre-release task but shouldn't be too long to test and deploy, just the challenge of retroactively running on the main production DB. I like your longer term view. It doesn't make much sense to separate scale in my view. @Behold3th, can you bring this up in the standup, it touches a couple of teams and skillsets so would be good to see who we need to get involved to do this cleanly. |
Been digging into this a bit more after speaking to @Behold3th The tl:dr:
Couple of changes needed on the DEGEN side: flagging @nonsensecodes for visibility. My suggestions:
How a bounty is created in DEGENPretty straightforward, DEGEN runs a couple of commands: Create the params: // src/app/commands/bounty/Bounty.ts (255)
params = this.buildBountyCreateNewParams(ctx.options.create);
console.log('/bounty create ' + params.title);
command = CreateNewBounty(guildMember, params); The params come from this function in the same file: // (302)
buildBountyCreateNewParams(ctxOptions: { [key: string]: any }): BountyCreateNew {
const [reward, symbol] = (ctxOptions.reward != null) ? ctxOptions.reward.split(' ') : [null, null];
const copies = (ctxOptions.copies == null || ctxOptions.copies <= 0) ? 1 : ctxOptions.copies;
let scale = reward.split('.')[1]?.length;
scale = (scale != null) ? scale : 0;
return {
title: ctxOptions.title,
reward: {
amount: reward,
currencySymbol: symbol,
scale: scale,
amountWithoutScale: reward.replace('.', ''),
},
copies: copies,
}; Note: the reward here is saved as a string (for now) and is NOT adjusted by scale, instead the scale is logged as a
// first it validates the reward:
await BountyUtils.validateReward(guildMember, reward); Pretty important point here, currently DEGEN will reject anything not denominated in BANK: // src/app/utils/BountyUtils.ts (65)
async validateReward(guildMember: GuildMember, reward: BountyReward): Promise<void> {
const ALLOWED_CURRENCIES = ['BANK'];
const allowedRegex = new RegExp(ALLOWED_CURRENCIES.join('|'), 'i');
const MAXIMUM_REWARD = 100000000.00;
if (isNaN(reward.amount) || reward.amount <= 0 || reward.amount > MAXIMUM_REWARD
|| !allowedRegex.test(reward.currencySymbol)) {
await guildMember.send({
content: `<@${guildMember.user.id}>\n` +
'Please enter a valid reward value: \n ' +
'- 100 million maximum currency\n ' +
'- accepted currencies: ETH, BANK',
});
throw new ValidationError('Please try another reward.');
}
}, Anyway, once the reward is validated, DEGEN pushes to the DB: // src/app/service/bounty/create/CreateNewBounty.ts (71)
const db: Db = await dbInstance.dbConnect(constants.DB_NAME_BOUNTY_BOARD);
const dbBounty = db.collection(constants.DB_COLLECTION_BOUNTIES);
const listOfPrepBounties = [];
for (let i = 0; i < params.copies; i++) {
listOfPrepBounties.push(generateBountyRecord(params, guildMember));
}
const dbInsertResult = await dbBounty.insertMany(listOfPrepBounties, { ordered: false });
//... (121)
export const generateBountyRecord = (bountyParams: BountyCreateNew, guildMember: GuildMember): any => {
// ...
reward: {
currency: bountyParams.reward.currencySymbol,
amount: new Int32(bountyParams.reward.amount),
scale: new Int32(bountyParams.reward.scale),
}, But it displays a different result to the user: // (87)
const messageOptions: MessageOptions = {
// ...
{ name: 'Reward', value: BountyUtils.formatBountyAmount(newBounty.reward.amount, newBounty.reward.scale) + ' ' + newBounty.reward.currency.toUpperCase(), inline: true },
// ...
};
await guildMember.send('Thank you! Does this look right?');
const message: Message = await guildMember.send(messageOptions); Where // src/app/utils/BountyUtils.ts (167)
formatBountyAmount(amount: number, scale: number): string {
return (amount / 10 ** scale).toString();
}, |
Closing as addressed in bountybot integration |
Describe the bug
Reward is (partially) defined as:
And on the bountyboard/frontend, we calculate bounty $BANK value as
reward.amount / (10 ^ reward.scale)
So an example, the bounty bank value would be:
5000 amount, 0 scale = 5000 BANK
10500 amount, 3 scale = 10.5 BANK
As it currently stands, this is not accounted for in the filters or the sort criteria. The bounty board just pulls in 5k vs 10.5k, which is incorrect.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Sorting and filtering should adjust for decimal places provided by the
scale
fieldThere's a couple of ways we could do this:
You can write mongo queries to handle this in the case of "reward", HOWEVER, this kinda sucks:
Client side
We could just pull all the data and do a second stage filter on the client, this still involves writing a lot of extra logic
Add a new field to the bounties reward object
I'd say this is the most sensible, here we just add a field like
total
which is simply calculated on Insert/Update asamount / 10 ^ scale
It's then trivial to just filter by "reward.total", and sort by "reward.total"
The text was updated successfully, but these errors were encountered: