{"id":21531986,"url":"https://github.com/chainbound/profit-sharing-protocols-research","last_synced_at":"2025-10-12T15:11:34.824Z","repository":{"id":109767287,"uuid":"511457664","full_name":"chainbound/profit-sharing-protocols-research","owner":"chainbound","description":null,"archived":false,"fork":false,"pushed_at":"2022-07-12T19:08:38.000Z","size":8106,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-24T06:29:46.993Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chainbound.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-07T09:07:50.000Z","updated_at":"2022-07-07T09:08:12.000Z","dependencies_parsed_at":"2023-06-11T17:45:31.212Z","dependency_job_id":null,"html_url":"https://github.com/chainbound/profit-sharing-protocols-research","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Fprofit-sharing-protocols-research","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Fprofit-sharing-protocols-research/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Fprofit-sharing-protocols-research/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Fprofit-sharing-protocols-research/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chainbound","download_url":"https://codeload.github.com/chainbound/profit-sharing-protocols-research/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244096047,"owners_count":20397328,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T02:18:26.049Z","updated_at":"2025-10-12T15:11:34.734Z","avatar_url":"https://github.com/chainbound.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Research: Profit Sharing Protocols\n\n## Synthetix\n\n### 1. Getting all fees\n* On every swap, a fee in sUSD is minted to the [Fee Address](https://etherscan.io/address/0xfeefeefeefeefeefeefeefeefeefeefeefeefeef)\n* With Apollo, we filter every `Transfer` event on `sUSD` where `from` == `address(0)`\nand `to` == `0xfeEFEEfeefEeFeefEEFEEfEeFeefEEFeeFEEFEeF`:\n\n* **Mainnet**\n```hcl\n// Last 180 days\nstart_time = format_date(\"02-01-2006 15:04\", \"01-01-2022 00:00\")\nend_time = format_date(\"02-01-2006 15:04\", \"06-06-2022 00:00\")\n\nquery \"susd_fee_mints\" {\n  chain = \"ethereum\"\n\n  contract {\n    address = \"0x57Ab1ec28D129707052df4dF418D58a2D46d5f51\"\n    abi = \"erc20.abi.json\"\n\n    event \"Transfer\" {\n      outputs = [\"from\", \"to\", \"value\"]\n    }\n  }\n\n  // Every time a synth swap is made, the fee is minted to\n  // the fee address. This is how we filter for those events.\n  filter = [\n    from == \"0x0000000000000000000000000000000000000000\",\n    to == \"0xfeEFEEfeefEeFeefEEFEEfEeFeefEEFeeFEEFEeF\"\n  ]\n\n  save {\n    timestamp = timestamp\n    block = blocknumber\n    tx = tx_hash\n\n    // Parse raw sUSD value\n    fee = parse_decimals(value, 18)\n  }\n}\n```\n\n* **Optimism**\n```hcl\n// Last 180 days\nstart_time = format_date(\"02-01-2006 15:04\", \"06-01-2022 00:00\")\nend_time = format_date(\"02-01-2006 15:04\", \"06-06-2022 00:00\")\n\nquery \"susd_fee_mints_optimism\" {\n  chain = \"optimism\"\n\n  contract {\n    address = \"0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9\"\n    abi = \"erc20.abi.json\"\n\n    event \"Transfer\" {\n      outputs = [\"from\", \"to\", \"value\"]\n    }\n  }\n\n  // Every time a synth swap is made, the fee is minted to\n  // the fee address. This is how we filter for those events.\n  filter = [\n    from == \"0x0000000000000000000000000000000000000000\",\n    to == \"0xfeEFEEfeefEeFeefEEFEEfEeFeefEEFeeFEEFEeF\"\n  ]\n\n  save {\n    timestamp = timestamp\n    block = blocknumber\n    tx = tx_hash\n\n    // Parse raw sUSD value\n    fee = parse_decimals(value, 18)\n  }\n}\n```\n\n### 2. Getting staked SNX over time\n* We need to get staked SNX (total collateral value) over time.\n* Problem: there is no global state variable keeping track of the amount of staked SNX or collateral ratio,\nit's all individual. The SNX you stake doesn't even leave your wallet, but you get minted a debt token (SDS)\nrepresenting your debt in USD.\n* To get all the addresses that ever staked SNX, we can filter all the `Mint` events on SDS.\n* We can use these addresses to get the SNX staked. Because it's not feasible to do it for all the addresses,\nwe can filter out the top holders, look at all their claims over time and get an idea of the total APY.\n* We can get the top SDS holders, get their share of the total staked SNX by looking at their collateral and collateral ratios, and then calculate the percentage of total fees they would make.\n\n### 3. Getting claimed SNX\n\n## GMX\n### 1. Getting all staked GMX\n* sGMX is the contract that holds all staked GMX, so we just have to get its balance over time.\n\n```hcl\n// Last 180 days\nstart_time = format_date(\"02-01-2006 15:04\", \"06-01-2022 00:00\")\nend_time = format_date(\"02-01-2006 15:04\", \"06-06-2022 00:00\")\n// 1hr interval\ntime_interval = 3600\n\n// Do this for both chains\nquery \"gmx_staked_avax\" {\n  chain = \"avax\"\n\n  contract {\n    abi = \"erc20.abi.json\"\n    // address = \"0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a\" # arbi\n    address = \"0x62edc0692BD897D2295872a9FFCac5425011c661\"\n\n    method \"balanceOf\" {\n      inputs = {\n        // _owner = \"0x908C4D94D34924765f1eDc22A1DD098397c59dD4\" # arbi\n        _owner = \"0x2bD10f8E93B3669b6d42E74eEedC65dd1B0a1342\"\n      }\n\n      outputs = [\"balance\"]\n    }\n  }\n\n  save {\n    time = timestamp\n    block = blocknumber\n\n    gmx_staked = parse_decimals(balance, 18)\n  }\n}\n\n```\n* The rest of the stats can be downloaded from https://stats.gmx.io\n\n## Maple\n\n### 1. Getting total amount of MPL staked over time\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainbound%2Fprofit-sharing-protocols-research","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchainbound%2Fprofit-sharing-protocols-research","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainbound%2Fprofit-sharing-protocols-research/lists"}