-
Notifications
You must be signed in to change notification settings - Fork 2
Reward Code Redemption endpoints #540
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
Conversation
api/v1_coins_post_redeem.go
Outdated
| if redeemCode != "" { | ||
| // Read and burn code in one go | ||
| // Use CTE to capture old is_used value before updating | ||
| sql := `WITH old_row AS ( |
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.
Intentional choice to push this query as far down into the function as possible so that arbitrary errors in code that is not the actual claim process will just return early with 4xx/5xx. Once we get to this point, we're burning it and grabbing it in a single query (while also checking if it had already been used).
Note that using a code for the wrong mint and using a code that doesn't exist both return the same error.
If we want that to be different, will need to rework this.
api/v1_coins_post_redeem.go
Outdated
|
|
||
| var rewardStateAddress string | ||
| var minVotes int | ||
| err = app.pool.QueryRow(c.Context(), `SELECT reward_manager_state, min_votes FROM sol_reward_manager_inits WHERE mint = @mint`, pgx.NamedArgs{ |
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.
Shortcut here to get min_votes from the table. Technically this could fail if the table has a different value than what's currently on chain. But that feels highly unlikely.
api/v1_coins_post_redeem.go
Outdated
| rewardClaim := oap_rewards.RewardClaim{ | ||
| RecipientEthAddress: userWalletAddress, | ||
| Amount: amount, | ||
| RewardID: "code", // TODO: Use shared constant/generator |
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.
this will depend on the result of the query, too, right? like if there's a "gift" reward the code will be the ID?
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.
All the use cases that use a redeemable code can use 'code' as the rewardId (these don't need to be unique across programatic rewards) and the code itself as the specifier.
api/v1_coins_post_redeem.go
Outdated
| "github.com/jackc/pgx/v5" | ||
| ) | ||
|
|
||
| func getAttestationSignatureForRewardClaimAuthority(rewardClaim oap_rewards.RewardClaim, claimAuthorityKey *ecdsa.PrivateKey) (string, error) { |
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.
doesn't this already exist?
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.
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.
Oh good call. I didn't know that was a thing.
a890130 to
e7b4088
Compare
e7b4088 to
41a5f21
Compare
41a5f21 to
7369b93
Compare
api/v1_coins_post_redeem.go
Outdated
|
|
||
| response, err := oap.Rewards.GetRewardAttestation(c.Context(), &v1.GetRewardAttestationRequest{ | ||
| EthRecipientAddress: userWalletAddress, | ||
| Amount: uint64(amount) / uint64(math.Pow10(int(coinDecimals))), // Convert from token decimals |
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.
Confirming this is all right?
Opted to re-use the handlers since there is very little difference in the logic between using a code and not using one.
Can split out if we don't love it.
Not going to work as-is, needs some stuff from an unmerged PR. But the bones are there.