Skip to content

Commit

Permalink
feat: add support for Balancer L2 BAL rewards (#1012)
Browse files Browse the repository at this point in the history
* feat: add support for Balancer L2 BAL rewards

* fix: balancer-v2 - remove unused code from childChainGauges.js
  • Loading branch information
zilayo authored Sep 23, 2023
1 parent 9ee7b24 commit 5477da2
Show file tree
Hide file tree
Showing 4 changed files with 363 additions and 47 deletions.
243 changes: 243 additions & 0 deletions src/adaptors/balancer-v2/abis/balancer_token_admin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
[
{
"inputs": [
{ "internalType": "contract IVault", "name": "vault", "type": "address" },
{
"internalType": "contract IBalancerToken",
"name": "balancerToken",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "rate",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "supply",
"type": "uint256"
}
],
"name": "MiningParametersUpdated",
"type": "event"
},
{
"inputs": [],
"name": "INITIAL_RATE",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "RATE_DENOMINATOR",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "RATE_REDUCTION_COEFFICIENT",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "RATE_REDUCTION_TIME",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "activate",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "available_supply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "futureEpochTimeWrite",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "future_epoch_time_write",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes4", "name": "selector", "type": "bytes4" }
],
"name": "getActionId",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getAuthorizer",
"outputs": [
{ "internalType": "contract IAuthorizer", "name": "", "type": "address" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getAvailableSupply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getBalancerToken",
"outputs": [
{
"internalType": "contract IBalancerToken",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getFutureEpochTime",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getInflationRate",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getMiningEpoch",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getStartEpochSupply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getStartEpochTime",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getVault",
"outputs": [
{ "internalType": "contract IVault", "name": "", "type": "address" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "mint",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "start", "type": "uint256" },
{ "internalType": "uint256", "name": "end", "type": "uint256" }
],
"name": "mintableInTimeframe",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "start", "type": "uint256" },
{ "internalType": "uint256", "name": "end", "type": "uint256" }
],
"name": "mintable_in_timeframe",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "rate",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "snapshot",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "startEpochTimeWrite",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "start_epoch_time_write",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "updateMiningParameters",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "update_mining_parameters",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
48 changes: 48 additions & 0 deletions src/adaptors/balancer-v2/childChainGauges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { request, gql } = require('graphql-request');
const { capitalizeFirstLetter } = require('../utils');

const urlBase = 'https://api.thegraph.com/subgraphs/name/balancer-labs';
const urlGaugesEthereum = `${urlBase}/balancer-gauges`;

// For reference - this is how chains are stored in the gauges subgraph
// const chainToEnum = {
// arbitrum: 0,
// xdai: 1,
// polygon: 2,
// optimism: 3,
// avalanche: 4,
// polygonZkEvm: 5,
// base: 6,
// };

const queryChildGauge = gql`
query ($chain: String!) {
rootGauges(where: { chain: $chain }) {
chain
id
recipient
relativeWeightCap
}
}
`;

/**
* @param chain chainString
* @returns array of: {chain, id (root gauge address on ethereum), recipient (gauge on child chain), relativeWeightCap}
*/
const getChildChainRootGauge = async (chain) => {
chain = capitalizeFirstLetter(chain);

const variables = { chain };
const { rootGauges } = await request(
urlGaugesEthereum,
queryChildGauge,
variables
);

return rootGauges;
};

module.exports = {
getChildChainRootGauge,
};
Loading

0 comments on commit 5477da2

Please sign in to comment.