Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ func NewApiServer(config config.Config) *ApiServer {
g.Get("/coins/:mint/members/count", app.v1CoinMembersCount)
g.Get("/coins/:mint/redeem", app.v1CoinsRedeem)
g.Get("/coins/:mint/redeem/:code", app.v1CoinsRedeemCode)
g.Post("/coins/:mint/redeem", app.requireAuthMiddleware, app.v1CoinsPostRedeem)
g.Post("/coins/:mint/redeem/:code", app.requireAuthMiddleware, app.v1CoinsPostRedeem)
g.Post("/coins", app.v1CreateCoin)
g.Post("/coins/:mint", app.v1UpdateCoin)

Expand Down
112 changes: 112 additions & 0 deletions api/swagger/swagger-v1-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,41 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/redeem_amount_response'
post:
tags:
- coins
operationId: Claim Coin Reward
description: 'Claims a coin reward for a given mint'
parameters:
- name: mint
in: path
description: The mint address of the coin
required: true
schema:
type: string
example: 9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM
- name: user_id
in: query
description: The user ID of the user making the request
required: true
schema:
type: string
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/claim_rewards_response'
'400':
description: Bad request - No coin reward available or already claimed
content:
application/json:
schema:
$ref: '#/components/schemas/reward_code_error_response'
'500':
description: Server error
content: {}
/coins/{mint}/redeem/{code}:
get:
tags:
Expand Down Expand Up @@ -395,6 +430,48 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/reward_code_error_response'
post:
tags:
- coins
operationId: Claim Coin Reward Code
description: 'Claims a coin reward using a given code'
parameters:
- name: mint
in: path
description: The mint address of the coin
required: true
schema:
type: string
example: 9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM
- name: code
in: path
description: The reward code to claim
required: true
schema:
type: string
example: XYZ123
- name: user_id
in: query
description: The user ID of the user making the request
required: true
schema:
type: string
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/claim_rewards_response'
'400':
description: Bad request - Code is invalid or already used
content:
application/json:
schema:
$ref: '#/components/schemas/reward_code_error_response'
'500':
description: Server error
content: {}
/rewards/code:
post:
tags:
Expand Down Expand Up @@ -11216,6 +11293,41 @@ components:
type: array
items:
$ref: '#/components/schemas/comment'
claim_rewards_response:
type: object
required:
- data
properties:
data:
type: array
items:
type: object
required:
- challengeId
- specifier
properties:
challengeId:
type: string
description: The challenge ID
example: "u"
specifier:
type: string
description: The challenge specifier
example: "7eP5n"
amount:
type: string
description: The reward amount
example: "1000000000"
signatures:
type: array
items:
type: string
description: Transaction signatures
example: ["5j7s1QjmRKFuDbCWMRVRNibSV2VAAEcNKP6HWU7GwPdXkBZvhz8n4vQl7bBq8tN4Rz9x1Kj3mP5wQ8rT2Y6zA"]
error:
type: string
description: Error message if claim failed
example: "Insufficient balance"
comment_replies_response:
required:
- latest_chain_block
Expand Down
77 changes: 77 additions & 0 deletions api/swagger/swagger-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3942,6 +3942,41 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/redeem_amount_response'
post:
tags:
- coins
operationId: Claim Coin Reward
description: 'Claims a coin reward for a given mint'
parameters:
- name: mint
in: path
description: The mint address of the coin
required: true
schema:
type: string
example: 9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM
- name: user_id
in: query
description: The user ID of the user making the request
required: true
schema:
type: string
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/claim_rewards_response'
'400':
description: Bad request - No coin reward available or already claimed
content:
application/json:
schema:
$ref: '#/components/schemas/reward_code_error_response'
'500':
description: Server error
content: {}
/coins/{mint}/redeem/{code}:
get:
tags:
Expand Down Expand Up @@ -3976,6 +4011,48 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/reward_code_error_response'
post:
tags:
- coins
operationId: Claim Coin Reward Code
description: 'Claims a coin reward using a given code'
parameters:
- name: mint
in: path
description: The mint address of the coin
required: true
schema:
type: string
example: 9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM
- name: code
in: path
description: The reward code to claim
required: true
schema:
type: string
example: XYZ123
- name: user_id
in: query
description: The user ID of the user making the request
required: true
schema:
type: string
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/claim_rewards_response'
'400':
description: Bad request - Code is invalid or already used
content:
application/json:
schema:
$ref: '#/components/schemas/reward_code_error_response'
'500':
description: Server error
content: {}
/rewards/claim:
post:
tags:
Expand Down
20 changes: 13 additions & 7 deletions api/v1_claim_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ func fetchAttestations(
hasAntiAbuseOracleAttestation bool,
minVotes int,
) ([]SenderAttestation, error) {

// Shuffle the validators
shuffled := slices.Clone(allValidators)
rand.Shuffle(len(shuffled), func(i, j int) {
Expand Down Expand Up @@ -355,6 +354,7 @@ func sendRewardClaimTransactions(
transactionSender *spl.TransactionSender,
rewardClaim RewardClaim,
attestations []SenderAttestation,
sourceTokenAccount *solana.PublicKey,
) ([]solana.Signature, error) {
// Transaction to send attestations in a separate transaction
partialTx := solana.NewTransactionBuilder()
Expand Down Expand Up @@ -445,14 +445,17 @@ func sendRewardClaimTransactions(
if err != nil {
return nil, err
}
if sourceTokenAccount == nil {
sourceTokenAccount = &state.TokenAccount
}
evaluateAttestationInstruction, err := reward_manager.NewEvaluateAttestationInstruction(
rewardClaim.RewardID,
rewardClaim.Specifier,
common.HexToAddress(rewardClaim.RecipientEthAddress),
rewardClaim.Amount*1e8, // Convert to wAUDIO wei
rewardClaim.Amount*rewardClaim.TokenDecimals, // Convert to token wei
common.HexToAddress(rewardClaim.ClaimAuthority),
rewardManagerClient.GetProgramStateAccount(),
state.TokenAccount,
*sourceTokenAccount,
rewardClaim.UserBank,
feePayer.PublicKey(),
)
Expand Down Expand Up @@ -552,6 +555,7 @@ func claimReward(
transactionSender,
rewardClaim,
attestations,
nil, // No ATA needed for AUDIO rewards
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -613,8 +617,9 @@ func getReward(rewardId string, rewardsList []rewards.Reward) (rewards.Reward, e

type RewardClaim struct {
rewards.RewardClaim
Handle string
UserBank solana.PublicKey
Handle string
UserBank solana.PublicKey
TokenDecimals uint64
}

type ClaimResult struct {
Expand Down Expand Up @@ -711,8 +716,9 @@ func (app *ApiServer) v1ClaimRewards(c *fiber.Ctx) error {
RecipientEthAddress: row.Wallet.String,
ClaimAuthority: antiAbuseOracle.DelegateOwnerWallet,
},
Handle: row.Handle.String,
UserBank: *bankAccount,
Handle: row.Handle.String,
UserBank: *bankAccount,
TokenDecimals: 8, // wAUDIO wei
}

validators := app.validators.GetNodes()
Expand Down
Loading