From 066ec4b66b5928625dff93bd031ecad034b9e507 Mon Sep 17 00:00:00 2001 From: SaiKiranMatta Date: Wed, 6 Aug 2025 11:20:47 +0530 Subject: [PATCH 01/10] chore: add affiliate earnings api reference --- .../endpoint/affiliate/get-earnings.mdx | 7 ++ api-reference/endpoint/get-fees.mdx | 4 +- api-reference/openapi.json | 117 ++++++++---------- docs.json | 6 + 4 files changed, 69 insertions(+), 65 deletions(-) create mode 100644 api-reference/endpoint/affiliate/get-earnings.mdx diff --git a/api-reference/endpoint/affiliate/get-earnings.mdx b/api-reference/endpoint/affiliate/get-earnings.mdx new file mode 100644 index 0000000..a6fcc1e --- /dev/null +++ b/api-reference/endpoint/affiliate/get-earnings.mdx @@ -0,0 +1,7 @@ +--- +title: 'Affiliate Earnings' +openapi: 'GET /earnings' +version: 1.0 +--- + +Total fees processed by Garden from genesis in USD. \ No newline at end of file diff --git a/api-reference/endpoint/get-fees.mdx b/api-reference/endpoint/get-fees.mdx index 79a62ca..df889b3 100644 --- a/api-reference/endpoint/get-fees.mdx +++ b/api-reference/endpoint/get-fees.mdx @@ -1,7 +1,7 @@ --- -title: 'Fees' +title: 'Total Fees' openapi: 'GET /fees' version: 1.0 --- -Returns total fees processed by Garden from genesis in USD, or affiliate fees if a `garden-app-id` header is provided. \ No newline at end of file +Total fees processed by Garden from genesis in USD. \ No newline at end of file diff --git a/api-reference/openapi.json b/api-reference/openapi.json index ab6ea87..0f37e3c 100644 --- a/api-reference/openapi.json +++ b/api-reference/openapi.json @@ -163,11 +163,12 @@ } ] }, - "AffiliateFeeItem": { + "AffiliateEarningsItem": { "type": "object", "properties": { "total_earnings": { - "type": "string" + "type": "string", + "description": "Total earnings in USD for the mentioned asset for the affiliate." }, "affiliate": { "type": "string" @@ -176,10 +177,12 @@ "$ref": "#/components/schemas/AffiliateFeeAsset" }, "claim_amount": { - "type": "string" + "type": "string", + "description": "Amount available for claiming in USD. Only included if the affiliate has not yet claimed their earnings." }, "claim_transaction": { - "$ref": "#/components/schemas/EVMTransaction" + "$ref": "#/components/schemas/EVMTransaction", + "description": "Transaction data for claiming earnings. Only included if the affiliate has not yet claimed their earnings." } }, "required": [ @@ -188,7 +191,7 @@ "asset" ] }, - "AffiliateFeesResponse": { + "AffiliateEarningsResponse": { "allOf": [ { "$ref": "#/components/schemas/Response" @@ -202,7 +205,7 @@ "result": { "type": "array", "items": { - "$ref": "#/components/schemas/AffiliateFeeItem" + "$ref": "#/components/schemas/AffiliateEarningsItem" } } } @@ -1352,69 +1355,17 @@ "/fees": { "get": { "summary": "Get swap fees.", - "security": [], - "parameters": [ - { - "in": "header", - "name": "garden-app-id", - "required": false, - "schema": { - "type": "string" - }, - "description": "Garden app ID for affiliate fee information" - } - ], "responses": { "200": { - "description": "Total swap fees or affiliate fees if garden-app-id is provided. For affiliate fees, claim_amount and claim_transaction are only included if the affiliate has not yet claimed their fees.", + "description": "Total swap fees.", "content": { "application/json": { "schema": { - "oneOf": [ - { - "$ref": "#/components/schemas/ResponseString", - "title": "Total Fees" - }, - { - "$ref": "#/components/schemas/AffiliateFeesResponse", - "title": "Affiliate Fees" - } - ] + "$ref": "#/components/schemas/ResponseString" }, - "examples": { - "total-fees": { - "summary": "Total Fees Response", - "value": { - "success": true, - "result": "2668122" - } - }, - "affiliate-fees": { - "summary": "Affiliate Fees Response", - "value": { - "success": true, - "result": [ - { - "total_earnings": "150750000", - "affiliate": "0x004Cc75ACF4132Fc08cB6a252E767804F303F729", - "asset": "ethereum:usdc", - "claim_amount": "50750000", - "claim_transaction": { - "to": "0x5EbEC4D8DA437b2BAD656D43d40fE412bA5D217a", - "value": "0x0", - "chain_id": 1, - "data": "0x4ede0ab7000000000000000000000000661ba32eb5f86cab358ddbb7f264b10c5825e2dd0000000000000000000000000000000000000000000000000000000000069780000000000000000000000000000000000000000000000000000000000000c3503331ff69aca609e06dcd4b97223667611d66bb4e8b56e26fc0ff53c49a1ed04d00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000", - "gas_limit": "0x30d40" - } - }, - { - "total_earnings": "3000000", - "affiliate": "0x004Cc75ACF4132Fc08cB6a252E767804F303F729", - "asset": "ethereum:cbbtc" - } - ] - } - } + "example": { + "status": "Ok", + "result": "2668122" } } } @@ -1765,6 +1716,46 @@ } } } + }, + "/earnings": { + "get": { + "summary": "Get affiliate earnings.", + "responses": { + "200": { + "description": "List of affiliate earnings.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AffiliateEarningsResponse" + }, + "example": { + "status": "Ok", + "result": [ + { + "total_earnings": "15075", + "affiliate": "0x004Cc75ACF4132Fc08cB6a252E767804F303F729", + "asset": "ethereum:usdc", + "claim_amount": "5075", + "claim_transaction": { + "to": "0x5EbEC4D8DA437b2BAD656D43d40fE412bA5D217a", + "value": "0x0", + "chain_id": 1, + "data": "0xce2631b8000000000000000000000000004cc75acf4132fc08cb6a252e767804f303f729000000000000000000000000d8a6e3fca403d79b6ad6216b60527f51cc967d39000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000041ff96072b331ff4d1b00c6fb61f3f69949a1bc7de7f48719aa016a7a6e2a6b28c159010947540573981978da376731693e9b272ba3b2c2fae24b1de854897c2671c00000000000000000000000000000000000000000000000000000000000000", + "gas_limit": "0x30d40" + } + }, + { + "total_earnings": "30000", + "affiliate": "0x004Cc75ACF4132Fc08cB6a252E767804F303F729", + "asset": "ethereum:cbbtc" + } + ] + } + } + } + } + } + } } } } \ No newline at end of file diff --git a/docs.json b/docs.json index b37835c..59f33c6 100644 --- a/docs.json +++ b/docs.json @@ -206,6 +206,12 @@ "api-reference/endpoint/orders/get-instant-refund-hash", "api-reference/endpoint/orders/patch" ] + }, + { + "group": "Affiliate", + "pages": [ + "api-reference/endpoint/affiliate/get-earnings" + ] } ] }, From 90a764457268d139653b5fea67c909c51a598a92 Mon Sep 17 00:00:00 2001 From: SaiKiranMatta Date: Wed, 6 Aug 2025 12:41:50 +0530 Subject: [PATCH 02/10] chore: add affiliate history api reference --- .../endpoint/affiliate/get-earnings.mdx | 2 +- .../endpoint/affiliate/get-history.mdx | 7 + api-reference/openapi.json | 124 ++++++++++++++++++ changelog.mdx | 8 ++ docs.json | 3 +- 5 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 api-reference/endpoint/affiliate/get-history.mdx diff --git a/api-reference/endpoint/affiliate/get-earnings.mdx b/api-reference/endpoint/affiliate/get-earnings.mdx index a6fcc1e..ca256d7 100644 --- a/api-reference/endpoint/affiliate/get-earnings.mdx +++ b/api-reference/endpoint/affiliate/get-earnings.mdx @@ -1,5 +1,5 @@ --- -title: 'Affiliate Earnings' +title: 'Earnings' openapi: 'GET /earnings' version: 1.0 --- diff --git a/api-reference/endpoint/affiliate/get-history.mdx b/api-reference/endpoint/affiliate/get-history.mdx new file mode 100644 index 0000000..0db8960 --- /dev/null +++ b/api-reference/endpoint/affiliate/get-history.mdx @@ -0,0 +1,7 @@ +--- +title: 'History' +openapi: 'GET /history' +version: 1.0 +--- + +Get credit and debit history of an affiliate. \ No newline at end of file diff --git a/api-reference/openapi.json b/api-reference/openapi.json index 0f37e3c..0c097eb 100644 --- a/api-reference/openapi.json +++ b/api-reference/openapi.json @@ -167,6 +167,10 @@ "type": "object", "properties": { "total_earnings": { + "type": "string", + "description": "Total earnings in asset units for the affiliate." + }, + "total_earnings_usd": { "type": "string", "description": "Total earnings in USD for the mentioned asset for the affiliate." }, @@ -177,6 +181,10 @@ "$ref": "#/components/schemas/AffiliateFeeAsset" }, "claim_amount": { + "type": "string", + "description": "Amount available for claiming in asset units. Only included if the affiliate has not yet claimed their earnings." + }, + "claim_amount_usd": { "type": "string", "description": "Amount available for claiming in USD. Only included if the affiliate has not yet claimed their earnings." }, @@ -187,6 +195,7 @@ }, "required": [ "total_earnings", + "total_earnings_usd", "affiliate", "asset" ] @@ -212,6 +221,106 @@ } ] }, + "AffiliateTransactionType": { + "type": "string", + "enum": [ + "credit", + "debit" + ], + "description": "Transaction type: 'credit' for earnings, 'debit' for claimed amounts." + }, + "AffiliateHistoryItem": { + "type": "object", + "properties": { + "asset": { + "$ref": "#/components/schemas/AffiliateFeeAsset" + }, + "affiliate": { + "type": "string", + "description": "The recipient address of the affiliate." + }, + "amount": { + "type": "string", + "description": "The amount of the transaction in asset units." + }, + "amount_usd": { + "type": "string", + "description": "The amount of the transaction in USD." + }, + "type": { + "$ref": "#/components/schemas/AffiliateTransactionType" + }, + "id": { + "type": "string", + "description": "Order ID for credit, transaction hash for debit." + }, + "timestamp": { + "type": "string" + } + }, + "required": [ + "asset", + "affiliate", + "amount", + "amount_usd", + "type", + "id", + "timestamp" + ] + }, + "PaginatedAffiliateHistoryItems": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/AffiliateHistoryItem" + } + }, + "total_earned": { + "type": "string", + "description": "Total earnings in USD for the affiliate." + }, + "total_claimed": { + "type": "string", + "description": "Total claimed earnings in USD for the affiliate." + }, + "page": { + "type": "integer" + }, + "total_pages": { + "type": "integer" + }, + "total_items": { + "type": "integer" + }, + "per_page": { + "type": "integer" + } + }, + "required": [ + "data", + "total_earned", + "total_claimed", + "page", + "total_pages", + "total_items", + "per_page" + ] + }, + "AffiliateHistoryResponse": { + "allOf": [ + {"$ref": "#/components/schemas/Response"}, + { + "type": "object", + "properties": { + "result": { + "$ref": "#/components/schemas/PaginatedAffiliateHistoryItems" + } + } + } + ] + }, "Asset": { "oneOf": [ { @@ -1756,6 +1865,21 @@ } } } + }, + "/history": { + "get": { + "summary": "Get credit and debit history of an affiliate.", + "responses": { + "200": { + "description": "Credit and debit history of an affiliate.", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/AffiliateHistoryResponse" } + } + } + } + } + } } } } \ No newline at end of file diff --git a/changelog.mdx b/changelog.mdx index 348bea8..9f9fece 100644 --- a/changelog.mdx +++ b/changelog.mdx @@ -2,6 +2,14 @@ title: "Changelog" description: "Product updates and announcements" --- + + + ### New endpoints + + - Add `/earnings` endpoint for fetching affiliate earnings + - Add `/history` endpoint for fetching affiliate history + + ### New endpoints diff --git a/docs.json b/docs.json index 59f33c6..d277567 100644 --- a/docs.json +++ b/docs.json @@ -210,7 +210,8 @@ { "group": "Affiliate", "pages": [ - "api-reference/endpoint/affiliate/get-earnings" + "api-reference/endpoint/affiliate/get-earnings", + "api-reference/endpoint/affiliate/get-history" ] } ] From 37f70ee09174f8131f94975fc99eef10cd354930 Mon Sep 17 00:00:00 2001 From: SaiKiranMatta Date: Wed, 6 Aug 2025 12:52:14 +0530 Subject: [PATCH 03/10] chore: update affiliate routes --- api-reference/endpoint/affiliate/get-earnings.mdx | 6 +++--- api-reference/endpoint/affiliate/get-history.mdx | 2 +- api-reference/openapi.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api-reference/endpoint/affiliate/get-earnings.mdx b/api-reference/endpoint/affiliate/get-earnings.mdx index ca256d7..fe1cba0 100644 --- a/api-reference/endpoint/affiliate/get-earnings.mdx +++ b/api-reference/endpoint/affiliate/get-earnings.mdx @@ -1,7 +1,7 @@ --- title: 'Earnings' -openapi: 'GET /earnings' +openapi: 'GET /affiliates/earnings' version: 1.0 ---- +--- -Total fees processed by Garden from genesis in USD. \ No newline at end of file +Get affiliate earnings and claimable amounts for different assets. diff --git a/api-reference/endpoint/affiliate/get-history.mdx b/api-reference/endpoint/affiliate/get-history.mdx index 0db8960..9a5c008 100644 --- a/api-reference/endpoint/affiliate/get-history.mdx +++ b/api-reference/endpoint/affiliate/get-history.mdx @@ -1,6 +1,6 @@ --- title: 'History' -openapi: 'GET /history' +openapi: 'GET /affiliates/history' version: 1.0 --- diff --git a/api-reference/openapi.json b/api-reference/openapi.json index 0c097eb..f1dd929 100644 --- a/api-reference/openapi.json +++ b/api-reference/openapi.json @@ -1826,7 +1826,7 @@ } } }, - "/earnings": { + "/affiliates/earnings": { "get": { "summary": "Get affiliate earnings.", "responses": { @@ -1866,7 +1866,7 @@ } } }, - "/history": { + "/affiliates/history": { "get": { "summary": "Get credit and debit history of an affiliate.", "responses": { From ca4fa7575d25566885b7723cbf2480777aaebcbb Mon Sep 17 00:00:00 2001 From: SaiKiranMatta Date: Wed, 6 Aug 2025 12:56:40 +0530 Subject: [PATCH 04/10] chore: update changelog --- changelog.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.mdx b/changelog.mdx index 9f9fece..460faaa 100644 --- a/changelog.mdx +++ b/changelog.mdx @@ -6,8 +6,8 @@ description: "Product updates and announcements" ### New endpoints - - Add `/earnings` endpoint for fetching affiliate earnings - - Add `/history` endpoint for fetching affiliate history + - Add `/affiliates/earnings` endpoint for fetching affiliate earnings + - Add `/affiliates/history` endpoint for fetching affiliate history From cac47487969587a3bb4315279278645dc06df51d Mon Sep 17 00:00:00 2001 From: SaiKiranMatta Date: Mon, 11 Aug 2025 11:03:50 +0530 Subject: [PATCH 05/10] chore: update affiliate earnings response --- api-reference/openapi.json | 39 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/api-reference/openapi.json b/api-reference/openapi.json index f1dd929..3c31aae 100644 --- a/api-reference/openapi.json +++ b/api-reference/openapi.json @@ -180,6 +180,10 @@ "asset": { "$ref": "#/components/schemas/AffiliateFeeAsset" }, + "token_address": { + "type": "string", + "description": "Contract address for the affiliate fee asset." + }, "claim_amount": { "type": "string", "description": "Amount available for claiming in asset units. Only included if the affiliate has not yet claimed their earnings." @@ -188,16 +192,21 @@ "type": "string", "description": "Amount available for claiming in USD. Only included if the affiliate has not yet claimed their earnings." }, - "claim_transaction": { - "$ref": "#/components/schemas/EVMTransaction", - "description": "Transaction data for claiming earnings. Only included if the affiliate has not yet claimed their earnings." + "claim_signature": { + "type": "string", + "description": "Signature for claiming earnings. Only included if the affiliate has not yet claimed their earnings." + }, + "claim_contract": { + "type": "string", + "description": "Contract address for claiming earnings. Only included if the affiliate has not yet claimed their earnings." } }, "required": [ "total_earnings", "total_earnings_usd", "affiliate", - "asset" + "asset", + "token_address" ] }, "AffiliateEarningsResponse": { @@ -1841,22 +1850,22 @@ "status": "Ok", "result": [ { - "total_earnings": "15075", + "total_earnings": "15075000000", + "total_earnings_usd": "15075", "affiliate": "0x004Cc75ACF4132Fc08cB6a252E767804F303F729", "asset": "ethereum:usdc", - "claim_amount": "5075", - "claim_transaction": { - "to": "0x5EbEC4D8DA437b2BAD656D43d40fE412bA5D217a", - "value": "0x0", - "chain_id": 1, - "data": "0xce2631b8000000000000000000000000004cc75acf4132fc08cb6a252e767804f303f729000000000000000000000000d8a6e3fca403d79b6ad6216b60527f51cc967d39000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000041ff96072b331ff4d1b00c6fb61f3f69949a1bc7de7f48719aa016a7a6e2a6b28c159010947540573981978da376731693e9b272ba3b2c2fae24b1de854897c2671c00000000000000000000000000000000000000000000000000000000000000", - "gas_limit": "0x30d40" - } + "token_address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", + "claim_amount": "5075000000", + "claim_amount_usd": "5075", + "claim_signature": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1b", + "claim_contract": "0x5EbEC4D8DA437b2BAD656D43d40fE412bA5D217a" }, { - "total_earnings": "30000", + "total_earnings": "30000000", + "total_earnings_usd": "30000", "affiliate": "0x004Cc75ACF4132Fc08cB6a252E767804F303F729", - "asset": "ethereum:cbbtc" + "asset": "ethereum:cbbtc", + "token_address": "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf" } ] } From 32acb97b2478ccf0af6248ec09d26a2805162727 Mon Sep 17 00:00:00 2001 From: SaiKiranMatta Date: Thu, 14 Aug 2025 12:36:35 +0530 Subject: [PATCH 06/10] chore: affiliate claim explanation --- developers/affiliate-fees.mdx | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/developers/affiliate-fees.mdx b/developers/affiliate-fees.mdx index e7e9d1c..093d771 100644 --- a/developers/affiliate-fees.mdx +++ b/developers/affiliate-fees.mdx @@ -160,3 +160,88 @@ For example, a 30 bps fee could be split by sending 10 bps in USDC to an Ethereu + +## How to Claim + +Affiliates can claim their earnings by first checking available amounts through the API, then submitting an on-chain transaction to the distributor contract. + +### Check Available Earnings + +First, call the earnings endpoint to get your claimable amounts: + + +```bash cURL +curl -X 'GET' 'https://api.garden.finance/v2/affiliates/earnings' \ + -H 'garden-app-id: YOUR_APP_ID' \ + -H 'accept: application/json' +``` + + + +```json Success +{ + "status": "Ok", + "result": [ + { + "total_earnings": "15075000000", + "total_earnings_usd": "15075", + "affiliate": "0x004Cc75ACF4132Fc08cB6a252E767804F303F729", + "asset": "ethereum:usdc", + "token_address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", + "claim_amount": "5075000000", + "claim_amount_usd": "5075", + "claim_signature": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1b", + "claim_contract": "0x5EbEC4D8DA437b2BAD656D43d40fE412bA5D217a" + } + ] +} +``` + + + + The `claim_amount`, `claim_amount_usd`, `claim_signature`, and `claim_contract` fields are only included when you have unclaimed earnings available. + + +### Claim Your Earnings + +To claim your earnings, you need to call the `claim` function on the distributor contract. Here's how to construct the transaction: + + + Make sure to call the claim function on the same chain where you received the rewards. For example, if your earnings are in `ethereum:usdc`, you should use the Ethereum mainnet RPC URL and chain configuration. + + +```javascript JavaScript +import { createWalletClient, http, parseAbi } from 'viem'; +import { privateKeyToAccount } from 'viem/accounts'; +import { mainnet } from 'viem/chains'; + +async function claimAffiliateEarnings(claimData) { + const account = privateKeyToAccount(''); + const client = createWalletClient({ + account, + chain: mainnet, + transport: http('YOUR_RPC_URL'), + }); + + const abi = parseAbi([ + 'function claim(tuple(address toAddress, address tokenAddress, uint256 totalRewards) _claim, bytes _signature) external' + ]); + + const claimParams = { + toAddress: claimData.affiliate, + tokenAddress: claimData.token_address, + totalRewards: BigInt(claimData.claim_amount) + }; + + const hash = await client.writeContract({ + address: claimData.claim_contract, + abi, + functionName: 'claim', + args: [claimParams, claimData.claim_signature] + }); + + const receipt = await client.waitForTransactionReceipt({ hash }); + return receipt; +} +``` + From 699eabc349d6ad4404d99b06391287cce2eff3e4 Mon Sep 17 00:00:00 2001 From: SaiKiranMatta Date: Mon, 18 Aug 2025 11:12:36 +0530 Subject: [PATCH 07/10] chore: update affiliate claims section --- developers/affiliate-fees.mdx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/developers/affiliate-fees.mdx b/developers/affiliate-fees.mdx index 093d771..21feaf5 100644 --- a/developers/affiliate-fees.mdx +++ b/developers/affiliate-fees.mdx @@ -163,21 +163,20 @@ For example, a 30 bps fee could be split by sending 10 bps in USDC to an Ethereu ## How to Claim -Affiliates can claim their earnings by first checking available amounts through the API, then submitting an on-chain transaction to the distributor contract. +The claiming process involves two steps: checking your available earnings through the API, then submitting an on-chain transaction to withdraw them. ### Check Available Earnings First, call the earnings endpoint to get your claimable amounts: - ```bash cURL curl -X 'GET' 'https://api.garden.finance/v2/affiliates/earnings' \ -H 'garden-app-id: YOUR_APP_ID' \ -H 'accept: application/json' ``` - - +Example response: + ```json Success { "status": "Ok", @@ -196,7 +195,6 @@ curl -X 'GET' 'https://api.garden.finance/v2/affiliates/earnings' \ ] } ``` - The `claim_amount`, `claim_amount_usd`, `claim_signature`, and `claim_contract` fields are only included when you have unclaimed earnings available. @@ -230,7 +228,7 @@ async function claimAffiliateEarnings(claimData) { const claimParams = { toAddress: claimData.affiliate, tokenAddress: claimData.token_address, - totalRewards: BigInt(claimData.claim_amount) + totalRewards: BigInt(claimData.total_earnings) }; const hash = await client.writeContract({ From 51e6ae1fef2a8807d1524744ee5601c3e99cfee1 Mon Sep 17 00:00:00 2001 From: SaiKiranMatta Date: Mon, 18 Aug 2025 17:19:03 +0530 Subject: [PATCH 08/10] chore: update claim code snippet --- developers/affiliate-fees.mdx | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/developers/affiliate-fees.mdx b/developers/affiliate-fees.mdx index 21feaf5..8d91fe8 100644 --- a/developers/affiliate-fees.mdx +++ b/developers/affiliate-fees.mdx @@ -209,36 +209,48 @@ To claim your earnings, you need to call the `claim` function on the distributor ```javascript JavaScript -import { createWalletClient, http, parseAbi } from 'viem'; +import { createWalletClient, createPublicClient, http, parseAbi } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; import { mainnet } from 'viem/chains'; async function claimAffiliateEarnings(claimData) { const account = privateKeyToAccount(''); - const client = createWalletClient({ + + // Create wallet client for sending transactions + const walletClient = createWalletClient({ account, chain: mainnet, transport: http('YOUR_RPC_URL'), }); + // Create public client for reading transaction receipts + const publicClient = createPublicClient({ + chain: mainnet, + transport: http('YOUR_RPC_URL'), + }); + + // Parse the ABI for the claim function const abi = parseAbi([ - 'function claim(tuple(address toAddress, address tokenAddress, uint256 totalRewards) _claim, bytes _signature) external' + 'function claim((address toAddress, address tokenAddress, uint256 totalRewards) _claim, bytes _signature)' ]); + // Prepare claim parameters const claimParams = { toAddress: claimData.affiliate, tokenAddress: claimData.token_address, totalRewards: BigInt(claimData.total_earnings) }; - const hash = await client.writeContract({ + // Execute the claim transaction + const hash = await walletClient.writeContract({ address: claimData.claim_contract, abi, functionName: 'claim', args: [claimParams, claimData.claim_signature] }); - const receipt = await client.waitForTransactionReceipt({ hash }); + // Wait for transaction receipt + const receipt = await publicClient.waitForTransactionReceipt({ hash }); return receipt; } ``` From 2b4c1f54f686bdec43848cef3bb341411eb8eb8a Mon Sep 17 00:00:00 2001 From: SaiKiranMatta Date: Thu, 21 Aug 2025 17:24:25 +0530 Subject: [PATCH 09/10] chore: remove affiliate history --- .../endpoint/affiliate/get-earnings.mdx | 2 +- .../endpoint/affiliate/get-history.mdx | 7 -- api-reference/openapi.json | 117 +----------------- changelog.mdx | 5 +- developers/affiliate-fees.mdx | 2 +- docs.json | 3 +- 6 files changed, 6 insertions(+), 130 deletions(-) delete mode 100644 api-reference/endpoint/affiliate/get-history.mdx diff --git a/api-reference/endpoint/affiliate/get-earnings.mdx b/api-reference/endpoint/affiliate/get-earnings.mdx index fe1cba0..1c5b119 100644 --- a/api-reference/endpoint/affiliate/get-earnings.mdx +++ b/api-reference/endpoint/affiliate/get-earnings.mdx @@ -1,6 +1,6 @@ --- title: 'Earnings' -openapi: 'GET /affiliates/earnings' +openapi: 'GET /apps/earnings' version: 1.0 --- diff --git a/api-reference/endpoint/affiliate/get-history.mdx b/api-reference/endpoint/affiliate/get-history.mdx deleted file mode 100644 index 9a5c008..0000000 --- a/api-reference/endpoint/affiliate/get-history.mdx +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: 'History' -openapi: 'GET /affiliates/history' -version: 1.0 ---- - -Get credit and debit history of an affiliate. \ No newline at end of file diff --git a/api-reference/openapi.json b/api-reference/openapi.json index 3c31aae..11956f5 100644 --- a/api-reference/openapi.json +++ b/api-reference/openapi.json @@ -230,106 +230,6 @@ } ] }, - "AffiliateTransactionType": { - "type": "string", - "enum": [ - "credit", - "debit" - ], - "description": "Transaction type: 'credit' for earnings, 'debit' for claimed amounts." - }, - "AffiliateHistoryItem": { - "type": "object", - "properties": { - "asset": { - "$ref": "#/components/schemas/AffiliateFeeAsset" - }, - "affiliate": { - "type": "string", - "description": "The recipient address of the affiliate." - }, - "amount": { - "type": "string", - "description": "The amount of the transaction in asset units." - }, - "amount_usd": { - "type": "string", - "description": "The amount of the transaction in USD." - }, - "type": { - "$ref": "#/components/schemas/AffiliateTransactionType" - }, - "id": { - "type": "string", - "description": "Order ID for credit, transaction hash for debit." - }, - "timestamp": { - "type": "string" - } - }, - "required": [ - "asset", - "affiliate", - "amount", - "amount_usd", - "type", - "id", - "timestamp" - ] - }, - "PaginatedAffiliateHistoryItems": { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/AffiliateHistoryItem" - } - }, - "total_earned": { - "type": "string", - "description": "Total earnings in USD for the affiliate." - }, - "total_claimed": { - "type": "string", - "description": "Total claimed earnings in USD for the affiliate." - }, - "page": { - "type": "integer" - }, - "total_pages": { - "type": "integer" - }, - "total_items": { - "type": "integer" - }, - "per_page": { - "type": "integer" - } - }, - "required": [ - "data", - "total_earned", - "total_claimed", - "page", - "total_pages", - "total_items", - "per_page" - ] - }, - "AffiliateHistoryResponse": { - "allOf": [ - {"$ref": "#/components/schemas/Response"}, - { - "type": "object", - "properties": { - "result": { - "$ref": "#/components/schemas/PaginatedAffiliateHistoryItems" - } - } - } - ] - }, "Asset": { "oneOf": [ { @@ -1835,7 +1735,7 @@ } } }, - "/affiliates/earnings": { + "/apps/earnings": { "get": { "summary": "Get affiliate earnings.", "responses": { @@ -1874,21 +1774,6 @@ } } } - }, - "/affiliates/history": { - "get": { - "summary": "Get credit and debit history of an affiliate.", - "responses": { - "200": { - "description": "Credit and debit history of an affiliate.", - "content": { - "application/json": { - "schema": { "$ref": "#/components/schemas/AffiliateHistoryResponse" } - } - } - } - } - } } } } \ No newline at end of file diff --git a/changelog.mdx b/changelog.mdx index 460faaa..1911a87 100644 --- a/changelog.mdx +++ b/changelog.mdx @@ -3,11 +3,10 @@ title: "Changelog" description: "Product updates and announcements" --- - + ### New endpoints - - Add `/affiliates/earnings` endpoint for fetching affiliate earnings - - Add `/affiliates/history` endpoint for fetching affiliate history + - Add `/apps/earnings` endpoint for fetching affiliate earnings diff --git a/developers/affiliate-fees.mdx b/developers/affiliate-fees.mdx index 8d91fe8..7a0d443 100644 --- a/developers/affiliate-fees.mdx +++ b/developers/affiliate-fees.mdx @@ -170,7 +170,7 @@ The claiming process involves two steps: checking your available earnings throug First, call the earnings endpoint to get your claimable amounts: ```bash cURL -curl -X 'GET' 'https://api.garden.finance/v2/affiliates/earnings' \ +curl -X 'GET' 'https://api.garden.finance/v2/apps/earnings' \ -H 'garden-app-id: YOUR_APP_ID' \ -H 'accept: application/json' ``` diff --git a/docs.json b/docs.json index d277567..59f33c6 100644 --- a/docs.json +++ b/docs.json @@ -210,8 +210,7 @@ { "group": "Affiliate", "pages": [ - "api-reference/endpoint/affiliate/get-earnings", - "api-reference/endpoint/affiliate/get-history" + "api-reference/endpoint/affiliate/get-earnings" ] } ] From da4ee217dc452db17402da519224d05eb03d0e12 Mon Sep 17 00:00:00 2001 From: SaiKiranMatta Date: Thu, 21 Aug 2025 17:31:03 +0530 Subject: [PATCH 10/10] chore: add description to affiliate response field --- api-reference/openapi.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api-reference/openapi.json b/api-reference/openapi.json index 11956f5..61dc6c1 100644 --- a/api-reference/openapi.json +++ b/api-reference/openapi.json @@ -175,7 +175,8 @@ "description": "Total earnings in USD for the mentioned asset for the affiliate." }, "affiliate": { - "type": "string" + "type": "string", + "description": "The address that will receive the earnings." }, "asset": { "$ref": "#/components/schemas/AffiliateFeeAsset"