├── .gitignore ├── LICENSE ├── README.md ├── abis ├── BFactory.json ├── BPool.json ├── BToken.json ├── BTokenBytes32.json ├── CRPFactory.json └── ConfigurableRightsPool.json ├── package.json ├── schema.graphql ├── src └── mappings │ ├── factory.ts │ ├── helpers.ts │ └── pool.ts ├── subgraph.kovan.yaml ├── subgraph.rinkeby.yaml ├── subgraph.ropsten.yaml ├── subgraph.yaml ├── tsconfig.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | node_modules/ 3 | src/types/ 4 | .DS_STORE 5 | yarn-error.log 6 | .idea 7 | .vscode 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 The Graph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Balancer Subgraph 2 | 3 | The graphql schema is still under heavy development and will likely have major breaking changes. 4 | 5 | Only the factory address is needed in subgraph.yaml, new pool addresses are automatically picked up using Graph Protocol's data source templates. 6 | 7 | 8 | ## Setup 9 | 10 | ### Prerequisites 11 | 12 | - Global Yarn Packages 13 | - ganache-cli 14 | - truffle 15 | - graph-cli 16 | - Docker 17 | 18 | ### Services 19 | 20 | Start a ganache chain using 0.0.0.0 as a host so docker can connect 21 | 22 | ``` 23 | ganache-cli -h 0.0.0.0 -d -l 4294967295 --allowUnlimitedContractSize 24 | ``` 25 | 26 | Run a local graph node 27 | 28 | ``` 29 | git clone https://github.com/graphprotocol/graph-node/ 30 | ``` 31 | 32 | Update ethereum value in docker-compose.yml to `ganache:http://host.docker.internal:8545` 33 | 34 | ``` 35 | cd graph-node/docker 36 | ``` 37 | 38 | ``` 39 | docker-compose up 40 | ``` 41 | 42 | To blow away graph-node settings 43 | 44 | ``` 45 | docker-compose kill && docker-compose rm -f && rm -rf data 46 | ``` 47 | 48 | ### Contracts 49 | 50 | Deploy balancer contracts using truffle. Using the `yarn deploy` script in balancer-dapp also makes this easy to test out the subgraph using the frontend. 51 | 52 | ### Subgraph 53 | 54 | Clone the balancer subgraph 55 | 56 | ``` 57 | git clone git@github.com:balancer-labs/balancer-subgraph.git 58 | ``` 59 | 60 | Update factory address in subgraph.yaml to the one listed as part of the deploy 61 | 62 | Install dependencies 63 | 64 | ``` 65 | yarn 66 | ``` 67 | 68 | Generate the graph code 69 | 70 | ``` 71 | yarn codegen 72 | ``` 73 | 74 | Create local node 75 | 76 | ``` 77 | yarn create:local 78 | ``` 79 | 80 | Deploy locally 81 | 82 | ``` 83 | yarn deploy:local 84 | ``` 85 | 86 | Any updates can be made to this repo and re-running `yarn deploy:local` without needing to re-initialize the environment. 87 | 88 | ## Running Locally With Parity Kovan Node 89 | 90 | Start Parity: 91 | 92 | ``` 93 | parity --chain=kovan --jsonrpc-interface=0.0.0.0 94 | ``` 95 | 96 | Update ethereum value in docker-compose.yml to `kovan:http://host.docker.internal:8545` 97 | 98 | Comment out try_ functions in pool.ts LN52-64 99 | 100 | ``` 101 | cd graph-node/docker 102 | ``` 103 | 104 | ``` 105 | docker-compose up 106 | ``` 107 | 108 | Create local node 109 | 110 | ``` 111 | yarn create:local 112 | ``` 113 | 114 | Deploy locally 115 | 116 | ``` 117 | yarn deploy:local 118 | ``` 119 | 120 | To blow away graph-node settings 121 | 122 | ``` 123 | docker-compose kill && docker-compose rm -f && rm -rf data 124 | ``` 125 | 126 | 127 | ## Queries 128 | 129 | GraphiQL interface can be accessed on a dev env at: http://127.0.0.1:8000/subgraphs/name/balancer-labs/balancer-subgraph 130 | 131 | **List of pools** 132 | ```GraphQL 133 | { 134 | pools { 135 | id 136 | controller 137 | publicSwap 138 | finalized 139 | swapFee 140 | totalWeight 141 | totalShares 142 | createTime 143 | joinsCount 144 | exitsCount 145 | swapsCount 146 | tokens { 147 | id 148 | poolId { 149 | id 150 | } 151 | address 152 | balance 153 | denormWeight 154 | } 155 | shares { 156 | id 157 | poolId { 158 | id 159 | } 160 | userAddress { 161 | id 162 | } 163 | } 164 | } 165 | } 166 | ``` 167 | 168 | **Pools with 2 tokens** 169 | ```GraphQL 170 | { 171 | pools (where: {tokensList_contains: ["0x5b1869d9a4c187f2eaa108f3062412ecf0526b24", "0xcfeb869f69431e42cdb54a4f4f105c19c080a601"]}) { 172 | id 173 | publicSwap 174 | swapFee 175 | tokensList 176 | tokens { 177 | id 178 | address 179 | balance 180 | denormWeight 181 | } 182 | } 183 | } 184 | ``` 185 | -------------------------------------------------------------------------------- /abis/BFactory.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "BFactory", 3 | "abi": [{ 4 | "inputs": [], 5 | "payable": false, 6 | "stateMutability": "nonpayable", 7 | "type": "constructor" 8 | }, { 9 | "anonymous": false, 10 | "inputs": [{ 11 | "indexed": true, 12 | "internalType": "address", 13 | "name": "caller", 14 | "type": "address" 15 | }, { 16 | "indexed": true, 17 | "internalType": "address", 18 | "name": "blabs", 19 | "type": "address" 20 | }], 21 | "name": "LOG_BLABS", 22 | "type": "event" 23 | }, { 24 | "anonymous": false, 25 | "inputs": [{ 26 | "indexed": true, 27 | "internalType": "address", 28 | "name": "caller", 29 | "type": "address" 30 | }, { 31 | "indexed": true, 32 | "internalType": "address", 33 | "name": "pool", 34 | "type": "address" 35 | }], 36 | "name": "LOG_NEW_POOL", 37 | "type": "event" 38 | }, { 39 | "constant": false, 40 | "inputs": [{ 41 | "internalType": "contract BPool", 42 | "name": "pool", 43 | "type": "address" 44 | }], 45 | "name": "collect", 46 | "outputs": [], 47 | "payable": false, 48 | "stateMutability": "nonpayable", 49 | "type": "function" 50 | }, { 51 | "constant": true, 52 | "inputs": [], 53 | "name": "getBLabs", 54 | "outputs": [{ 55 | "internalType": "address", 56 | "name": "", 57 | "type": "address" 58 | }], 59 | "payable": false, 60 | "stateMutability": "view", 61 | "type": "function" 62 | }, { 63 | "constant": true, 64 | "inputs": [], 65 | "name": "getColor", 66 | "outputs": [{ 67 | "internalType": "bytes32", 68 | "name": "", 69 | "type": "bytes32" 70 | }], 71 | "payable": false, 72 | "stateMutability": "view", 73 | "type": "function" 74 | }, { 75 | "constant": true, 76 | "inputs": [{ 77 | "internalType": "address", 78 | "name": "b", 79 | "type": "address" 80 | }], 81 | "name": "isBPool", 82 | "outputs": [{ 83 | "internalType": "bool", 84 | "name": "", 85 | "type": "bool" 86 | }], 87 | "payable": false, 88 | "stateMutability": "view", 89 | "type": "function" 90 | }, { 91 | "constant": false, 92 | "inputs": [], 93 | "name": "newBPool", 94 | "outputs": [{ 95 | "internalType": "contract BPool", 96 | "name": "", 97 | "type": "address" 98 | }], 99 | "payable": false, 100 | "stateMutability": "nonpayable", 101 | "type": "function" 102 | }, { 103 | "constant": false, 104 | "inputs": [{ 105 | "internalType": "address", 106 | "name": "b", 107 | "type": "address" 108 | }], 109 | "name": "setBLabs", 110 | "outputs": [], 111 | "payable": false, 112 | "stateMutability": "nonpayable", 113 | "type": "function" 114 | }] 115 | } -------------------------------------------------------------------------------- /abis/BPool.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "BPool", 3 | "abi": [ 4 | { 5 | "inputs": [], 6 | "payable": false, 7 | "stateMutability": "nonpayable", 8 | "type": "constructor" 9 | }, 10 | { 11 | "anonymous": false, 12 | "inputs": [ 13 | { 14 | "indexed": true, 15 | "internalType": "address", 16 | "name": "src", 17 | "type": "address" 18 | }, 19 | { 20 | "indexed": true, 21 | "internalType": "address", 22 | "name": "dst", 23 | "type": "address" 24 | }, 25 | { 26 | "indexed": false, 27 | "internalType": "uint256", 28 | "name": "amt", 29 | "type": "uint256" 30 | } 31 | ], 32 | "name": "Approval", 33 | "type": "event" 34 | }, 35 | { 36 | "anonymous": true, 37 | "inputs": [ 38 | { 39 | "indexed": true, 40 | "internalType": "bytes4", 41 | "name": "sig", 42 | "type": "bytes4" 43 | }, 44 | { 45 | "indexed": true, 46 | "internalType": "address", 47 | "name": "caller", 48 | "type": "address" 49 | }, 50 | { 51 | "indexed": false, 52 | "internalType": "bytes", 53 | "name": "data", 54 | "type": "bytes" 55 | } 56 | ], 57 | "name": "LOG_CALL", 58 | "type": "event" 59 | }, 60 | { 61 | "anonymous": false, 62 | "inputs": [ 63 | { 64 | "indexed": true, 65 | "internalType": "address", 66 | "name": "caller", 67 | "type": "address" 68 | }, 69 | { 70 | "indexed": true, 71 | "internalType": "address", 72 | "name": "tokenOut", 73 | "type": "address" 74 | }, 75 | { 76 | "indexed": false, 77 | "internalType": "uint256", 78 | "name": "tokenAmountOut", 79 | "type": "uint256" 80 | } 81 | ], 82 | "name": "LOG_EXIT", 83 | "type": "event" 84 | }, 85 | { 86 | "anonymous": false, 87 | "inputs": [ 88 | { 89 | "indexed": true, 90 | "internalType": "address", 91 | "name": "caller", 92 | "type": "address" 93 | }, 94 | { 95 | "indexed": true, 96 | "internalType": "address", 97 | "name": "tokenIn", 98 | "type": "address" 99 | }, 100 | { 101 | "indexed": false, 102 | "internalType": "uint256", 103 | "name": "tokenAmountIn", 104 | "type": "uint256" 105 | } 106 | ], 107 | "name": "LOG_JOIN", 108 | "type": "event" 109 | }, 110 | { 111 | "anonymous": false, 112 | "inputs": [ 113 | { 114 | "indexed": true, 115 | "internalType": "address", 116 | "name": "caller", 117 | "type": "address" 118 | }, 119 | { 120 | "indexed": true, 121 | "internalType": "address", 122 | "name": "tokenIn", 123 | "type": "address" 124 | }, 125 | { 126 | "indexed": true, 127 | "internalType": "address", 128 | "name": "tokenOut", 129 | "type": "address" 130 | }, 131 | { 132 | "indexed": false, 133 | "internalType": "uint256", 134 | "name": "tokenAmountIn", 135 | "type": "uint256" 136 | }, 137 | { 138 | "indexed": false, 139 | "internalType": "uint256", 140 | "name": "tokenAmountOut", 141 | "type": "uint256" 142 | } 143 | ], 144 | "name": "LOG_SWAP", 145 | "type": "event" 146 | }, 147 | { 148 | "anonymous": false, 149 | "inputs": [ 150 | { 151 | "indexed": true, 152 | "internalType": "address", 153 | "name": "src", 154 | "type": "address" 155 | }, 156 | { 157 | "indexed": true, 158 | "internalType": "address", 159 | "name": "dst", 160 | "type": "address" 161 | }, 162 | { 163 | "indexed": false, 164 | "internalType": "uint256", 165 | "name": "amt", 166 | "type": "uint256" 167 | } 168 | ], 169 | "name": "Transfer", 170 | "type": "event" 171 | }, 172 | { 173 | "constant": true, 174 | "inputs": [], 175 | "name": "BONE", 176 | "outputs": [ 177 | { 178 | "internalType": "uint256", 179 | "name": "", 180 | "type": "uint256" 181 | } 182 | ], 183 | "payable": false, 184 | "stateMutability": "view", 185 | "type": "function" 186 | }, 187 | { 188 | "constant": true, 189 | "inputs": [], 190 | "name": "BPOW_PRECISION", 191 | "outputs": [ 192 | { 193 | "internalType": "uint256", 194 | "name": "", 195 | "type": "uint256" 196 | } 197 | ], 198 | "payable": false, 199 | "stateMutability": "view", 200 | "type": "function" 201 | }, 202 | { 203 | "constant": true, 204 | "inputs": [], 205 | "name": "EXIT_FEE", 206 | "outputs": [ 207 | { 208 | "internalType": "uint256", 209 | "name": "", 210 | "type": "uint256" 211 | } 212 | ], 213 | "payable": false, 214 | "stateMutability": "view", 215 | "type": "function" 216 | }, 217 | { 218 | "constant": true, 219 | "inputs": [], 220 | "name": "INIT_POOL_SUPPLY", 221 | "outputs": [ 222 | { 223 | "internalType": "uint256", 224 | "name": "", 225 | "type": "uint256" 226 | } 227 | ], 228 | "payable": false, 229 | "stateMutability": "view", 230 | "type": "function" 231 | }, 232 | { 233 | "constant": true, 234 | "inputs": [], 235 | "name": "MAX_BOUND_TOKENS", 236 | "outputs": [ 237 | { 238 | "internalType": "uint256", 239 | "name": "", 240 | "type": "uint256" 241 | } 242 | ], 243 | "payable": false, 244 | "stateMutability": "view", 245 | "type": "function" 246 | }, 247 | { 248 | "constant": true, 249 | "inputs": [], 250 | "name": "MAX_BPOW_BASE", 251 | "outputs": [ 252 | { 253 | "internalType": "uint256", 254 | "name": "", 255 | "type": "uint256" 256 | } 257 | ], 258 | "payable": false, 259 | "stateMutability": "view", 260 | "type": "function" 261 | }, 262 | { 263 | "constant": true, 264 | "inputs": [], 265 | "name": "MAX_FEE", 266 | "outputs": [ 267 | { 268 | "internalType": "uint256", 269 | "name": "", 270 | "type": "uint256" 271 | } 272 | ], 273 | "payable": false, 274 | "stateMutability": "view", 275 | "type": "function" 276 | }, 277 | { 278 | "constant": true, 279 | "inputs": [], 280 | "name": "MAX_TOTAL_WEIGHT", 281 | "outputs": [ 282 | { 283 | "internalType": "uint256", 284 | "name": "", 285 | "type": "uint256" 286 | } 287 | ], 288 | "payable": false, 289 | "stateMutability": "view", 290 | "type": "function" 291 | }, 292 | { 293 | "constant": true, 294 | "inputs": [], 295 | "name": "MAX_WEIGHT", 296 | "outputs": [ 297 | { 298 | "internalType": "uint256", 299 | "name": "", 300 | "type": "uint256" 301 | } 302 | ], 303 | "payable": false, 304 | "stateMutability": "view", 305 | "type": "function" 306 | }, 307 | { 308 | "constant": true, 309 | "inputs": [], 310 | "name": "MIN_BALANCE", 311 | "outputs": [ 312 | { 313 | "internalType": "uint256", 314 | "name": "", 315 | "type": "uint256" 316 | } 317 | ], 318 | "payable": false, 319 | "stateMutability": "view", 320 | "type": "function" 321 | }, 322 | { 323 | "constant": true, 324 | "inputs": [], 325 | "name": "MIN_BOUND_TOKENS", 326 | "outputs": [ 327 | { 328 | "internalType": "uint256", 329 | "name": "", 330 | "type": "uint256" 331 | } 332 | ], 333 | "payable": false, 334 | "stateMutability": "view", 335 | "type": "function" 336 | }, 337 | { 338 | "constant": true, 339 | "inputs": [], 340 | "name": "MIN_BPOW_BASE", 341 | "outputs": [ 342 | { 343 | "internalType": "uint256", 344 | "name": "", 345 | "type": "uint256" 346 | } 347 | ], 348 | "payable": false, 349 | "stateMutability": "view", 350 | "type": "function" 351 | }, 352 | { 353 | "constant": true, 354 | "inputs": [], 355 | "name": "MIN_FEE", 356 | "outputs": [ 357 | { 358 | "internalType": "uint256", 359 | "name": "", 360 | "type": "uint256" 361 | } 362 | ], 363 | "payable": false, 364 | "stateMutability": "view", 365 | "type": "function" 366 | }, 367 | { 368 | "constant": true, 369 | "inputs": [], 370 | "name": "MIN_WEIGHT", 371 | "outputs": [ 372 | { 373 | "internalType": "uint256", 374 | "name": "", 375 | "type": "uint256" 376 | } 377 | ], 378 | "payable": false, 379 | "stateMutability": "view", 380 | "type": "function" 381 | }, 382 | { 383 | "constant": true, 384 | "inputs": [ 385 | { 386 | "internalType": "address", 387 | "name": "src", 388 | "type": "address" 389 | }, 390 | { 391 | "internalType": "address", 392 | "name": "dst", 393 | "type": "address" 394 | } 395 | ], 396 | "name": "allowance", 397 | "outputs": [ 398 | { 399 | "internalType": "uint256", 400 | "name": "", 401 | "type": "uint256" 402 | } 403 | ], 404 | "payable": false, 405 | "stateMutability": "view", 406 | "type": "function" 407 | }, 408 | { 409 | "constant": false, 410 | "inputs": [ 411 | { 412 | "internalType": "address", 413 | "name": "dst", 414 | "type": "address" 415 | }, 416 | { 417 | "internalType": "uint256", 418 | "name": "amt", 419 | "type": "uint256" 420 | } 421 | ], 422 | "name": "approve", 423 | "outputs": [ 424 | { 425 | "internalType": "bool", 426 | "name": "", 427 | "type": "bool" 428 | } 429 | ], 430 | "payable": false, 431 | "stateMutability": "nonpayable", 432 | "type": "function" 433 | }, 434 | { 435 | "constant": true, 436 | "inputs": [ 437 | { 438 | "internalType": "address", 439 | "name": "whom", 440 | "type": "address" 441 | } 442 | ], 443 | "name": "balanceOf", 444 | "outputs": [ 445 | { 446 | "internalType": "uint256", 447 | "name": "", 448 | "type": "uint256" 449 | } 450 | ], 451 | "payable": false, 452 | "stateMutability": "view", 453 | "type": "function" 454 | }, 455 | { 456 | "constant": false, 457 | "inputs": [ 458 | { 459 | "internalType": "address", 460 | "name": "token", 461 | "type": "address" 462 | }, 463 | { 464 | "internalType": "uint256", 465 | "name": "balance", 466 | "type": "uint256" 467 | }, 468 | { 469 | "internalType": "uint256", 470 | "name": "denorm", 471 | "type": "uint256" 472 | } 473 | ], 474 | "name": "bind", 475 | "outputs": [], 476 | "payable": false, 477 | "stateMutability": "nonpayable", 478 | "type": "function" 479 | }, 480 | { 481 | "constant": true, 482 | "inputs": [ 483 | { 484 | "internalType": "uint256", 485 | "name": "tokenBalanceIn", 486 | "type": "uint256" 487 | }, 488 | { 489 | "internalType": "uint256", 490 | "name": "tokenWeightIn", 491 | "type": "uint256" 492 | }, 493 | { 494 | "internalType": "uint256", 495 | "name": "tokenBalanceOut", 496 | "type": "uint256" 497 | }, 498 | { 499 | "internalType": "uint256", 500 | "name": "tokenWeightOut", 501 | "type": "uint256" 502 | }, 503 | { 504 | "internalType": "uint256", 505 | "name": "tokenAmountOut", 506 | "type": "uint256" 507 | }, 508 | { 509 | "internalType": "uint256", 510 | "name": "swapFee", 511 | "type": "uint256" 512 | } 513 | ], 514 | "name": "calcInGivenOut", 515 | "outputs": [ 516 | { 517 | "internalType": "uint256", 518 | "name": "tokenAmountIn", 519 | "type": "uint256" 520 | } 521 | ], 522 | "payable": false, 523 | "stateMutability": "pure", 524 | "type": "function" 525 | }, 526 | { 527 | "constant": true, 528 | "inputs": [ 529 | { 530 | "internalType": "uint256", 531 | "name": "tokenBalanceIn", 532 | "type": "uint256" 533 | }, 534 | { 535 | "internalType": "uint256", 536 | "name": "tokenWeightIn", 537 | "type": "uint256" 538 | }, 539 | { 540 | "internalType": "uint256", 541 | "name": "tokenBalanceOut", 542 | "type": "uint256" 543 | }, 544 | { 545 | "internalType": "uint256", 546 | "name": "tokenWeightOut", 547 | "type": "uint256" 548 | }, 549 | { 550 | "internalType": "uint256", 551 | "name": "tokenAmountIn", 552 | "type": "uint256" 553 | }, 554 | { 555 | "internalType": "uint256", 556 | "name": "swapFee", 557 | "type": "uint256" 558 | } 559 | ], 560 | "name": "calcOutGivenIn", 561 | "outputs": [ 562 | { 563 | "internalType": "uint256", 564 | "name": "tokenAmountOut", 565 | "type": "uint256" 566 | } 567 | ], 568 | "payable": false, 569 | "stateMutability": "pure", 570 | "type": "function" 571 | }, 572 | { 573 | "constant": true, 574 | "inputs": [ 575 | { 576 | "internalType": "uint256", 577 | "name": "tokenBalanceOut", 578 | "type": "uint256" 579 | }, 580 | { 581 | "internalType": "uint256", 582 | "name": "tokenWeightOut", 583 | "type": "uint256" 584 | }, 585 | { 586 | "internalType": "uint256", 587 | "name": "poolSupply", 588 | "type": "uint256" 589 | }, 590 | { 591 | "internalType": "uint256", 592 | "name": "totalWeight", 593 | "type": "uint256" 594 | }, 595 | { 596 | "internalType": "uint256", 597 | "name": "tokenAmountOut", 598 | "type": "uint256" 599 | }, 600 | { 601 | "internalType": "uint256", 602 | "name": "swapFee", 603 | "type": "uint256" 604 | } 605 | ], 606 | "name": "calcPoolInGivenSingleOut", 607 | "outputs": [ 608 | { 609 | "internalType": "uint256", 610 | "name": "poolAmountIn", 611 | "type": "uint256" 612 | } 613 | ], 614 | "payable": false, 615 | "stateMutability": "pure", 616 | "type": "function" 617 | }, 618 | { 619 | "constant": true, 620 | "inputs": [ 621 | { 622 | "internalType": "uint256", 623 | "name": "tokenBalanceIn", 624 | "type": "uint256" 625 | }, 626 | { 627 | "internalType": "uint256", 628 | "name": "tokenWeightIn", 629 | "type": "uint256" 630 | }, 631 | { 632 | "internalType": "uint256", 633 | "name": "poolSupply", 634 | "type": "uint256" 635 | }, 636 | { 637 | "internalType": "uint256", 638 | "name": "totalWeight", 639 | "type": "uint256" 640 | }, 641 | { 642 | "internalType": "uint256", 643 | "name": "tokenAmountIn", 644 | "type": "uint256" 645 | }, 646 | { 647 | "internalType": "uint256", 648 | "name": "swapFee", 649 | "type": "uint256" 650 | } 651 | ], 652 | "name": "calcPoolOutGivenSingleIn", 653 | "outputs": [ 654 | { 655 | "internalType": "uint256", 656 | "name": "poolAmountOut", 657 | "type": "uint256" 658 | } 659 | ], 660 | "payable": false, 661 | "stateMutability": "pure", 662 | "type": "function" 663 | }, 664 | { 665 | "constant": true, 666 | "inputs": [ 667 | { 668 | "internalType": "uint256", 669 | "name": "tokenBalanceIn", 670 | "type": "uint256" 671 | }, 672 | { 673 | "internalType": "uint256", 674 | "name": "tokenWeightIn", 675 | "type": "uint256" 676 | }, 677 | { 678 | "internalType": "uint256", 679 | "name": "poolSupply", 680 | "type": "uint256" 681 | }, 682 | { 683 | "internalType": "uint256", 684 | "name": "totalWeight", 685 | "type": "uint256" 686 | }, 687 | { 688 | "internalType": "uint256", 689 | "name": "poolAmountOut", 690 | "type": "uint256" 691 | }, 692 | { 693 | "internalType": "uint256", 694 | "name": "swapFee", 695 | "type": "uint256" 696 | } 697 | ], 698 | "name": "calcSingleInGivenPoolOut", 699 | "outputs": [ 700 | { 701 | "internalType": "uint256", 702 | "name": "tokenAmountIn", 703 | "type": "uint256" 704 | } 705 | ], 706 | "payable": false, 707 | "stateMutability": "pure", 708 | "type": "function" 709 | }, 710 | { 711 | "constant": true, 712 | "inputs": [ 713 | { 714 | "internalType": "uint256", 715 | "name": "tokenBalanceOut", 716 | "type": "uint256" 717 | }, 718 | { 719 | "internalType": "uint256", 720 | "name": "tokenWeightOut", 721 | "type": "uint256" 722 | }, 723 | { 724 | "internalType": "uint256", 725 | "name": "poolSupply", 726 | "type": "uint256" 727 | }, 728 | { 729 | "internalType": "uint256", 730 | "name": "totalWeight", 731 | "type": "uint256" 732 | }, 733 | { 734 | "internalType": "uint256", 735 | "name": "poolAmountIn", 736 | "type": "uint256" 737 | }, 738 | { 739 | "internalType": "uint256", 740 | "name": "swapFee", 741 | "type": "uint256" 742 | } 743 | ], 744 | "name": "calcSingleOutGivenPoolIn", 745 | "outputs": [ 746 | { 747 | "internalType": "uint256", 748 | "name": "tokenAmountOut", 749 | "type": "uint256" 750 | } 751 | ], 752 | "payable": false, 753 | "stateMutability": "pure", 754 | "type": "function" 755 | }, 756 | { 757 | "constant": true, 758 | "inputs": [ 759 | { 760 | "internalType": "uint256", 761 | "name": "tokenBalanceIn", 762 | "type": "uint256" 763 | }, 764 | { 765 | "internalType": "uint256", 766 | "name": "tokenWeightIn", 767 | "type": "uint256" 768 | }, 769 | { 770 | "internalType": "uint256", 771 | "name": "tokenBalanceOut", 772 | "type": "uint256" 773 | }, 774 | { 775 | "internalType": "uint256", 776 | "name": "tokenWeightOut", 777 | "type": "uint256" 778 | }, 779 | { 780 | "internalType": "uint256", 781 | "name": "swapFee", 782 | "type": "uint256" 783 | } 784 | ], 785 | "name": "calcSpotPrice", 786 | "outputs": [ 787 | { 788 | "internalType": "uint256", 789 | "name": "spotPrice", 790 | "type": "uint256" 791 | } 792 | ], 793 | "payable": false, 794 | "stateMutability": "pure", 795 | "type": "function" 796 | }, 797 | { 798 | "constant": true, 799 | "inputs": [], 800 | "name": "decimals", 801 | "outputs": [ 802 | { 803 | "internalType": "uint8", 804 | "name": "", 805 | "type": "uint8" 806 | } 807 | ], 808 | "payable": false, 809 | "stateMutability": "view", 810 | "type": "function" 811 | }, 812 | { 813 | "constant": false, 814 | "inputs": [ 815 | { 816 | "internalType": "address", 817 | "name": "dst", 818 | "type": "address" 819 | }, 820 | { 821 | "internalType": "uint256", 822 | "name": "amt", 823 | "type": "uint256" 824 | } 825 | ], 826 | "name": "decreaseApproval", 827 | "outputs": [ 828 | { 829 | "internalType": "bool", 830 | "name": "", 831 | "type": "bool" 832 | } 833 | ], 834 | "payable": false, 835 | "stateMutability": "nonpayable", 836 | "type": "function" 837 | }, 838 | { 839 | "constant": false, 840 | "inputs": [ 841 | { 842 | "internalType": "uint256", 843 | "name": "poolAmountIn", 844 | "type": "uint256" 845 | }, 846 | { 847 | "internalType": "uint256[]", 848 | "name": "minAmountsOut", 849 | "type": "uint256[]" 850 | } 851 | ], 852 | "name": "exitPool", 853 | "outputs": [], 854 | "payable": false, 855 | "stateMutability": "nonpayable", 856 | "type": "function" 857 | }, 858 | { 859 | "constant": false, 860 | "inputs": [ 861 | { 862 | "internalType": "address", 863 | "name": "tokenOut", 864 | "type": "address" 865 | }, 866 | { 867 | "internalType": "uint256", 868 | "name": "tokenAmountOut", 869 | "type": "uint256" 870 | }, 871 | { 872 | "internalType": "uint256", 873 | "name": "maxPoolAmountIn", 874 | "type": "uint256" 875 | } 876 | ], 877 | "name": "exitswapExternAmountOut", 878 | "outputs": [ 879 | { 880 | "internalType": "uint256", 881 | "name": "poolAmountIn", 882 | "type": "uint256" 883 | } 884 | ], 885 | "payable": false, 886 | "stateMutability": "nonpayable", 887 | "type": "function" 888 | }, 889 | { 890 | "constant": false, 891 | "inputs": [ 892 | { 893 | "internalType": "address", 894 | "name": "tokenOut", 895 | "type": "address" 896 | }, 897 | { 898 | "internalType": "uint256", 899 | "name": "poolAmountIn", 900 | "type": "uint256" 901 | }, 902 | { 903 | "internalType": "uint256", 904 | "name": "minAmountOut", 905 | "type": "uint256" 906 | } 907 | ], 908 | "name": "exitswapPoolAmountIn", 909 | "outputs": [ 910 | { 911 | "internalType": "uint256", 912 | "name": "tokenAmountOut", 913 | "type": "uint256" 914 | } 915 | ], 916 | "payable": false, 917 | "stateMutability": "nonpayable", 918 | "type": "function" 919 | }, 920 | { 921 | "constant": false, 922 | "inputs": [], 923 | "name": "finalize", 924 | "outputs": [], 925 | "payable": false, 926 | "stateMutability": "nonpayable", 927 | "type": "function" 928 | }, 929 | { 930 | "constant": true, 931 | "inputs": [ 932 | { 933 | "internalType": "address", 934 | "name": "token", 935 | "type": "address" 936 | } 937 | ], 938 | "name": "getBalance", 939 | "outputs": [ 940 | { 941 | "internalType": "uint256", 942 | "name": "", 943 | "type": "uint256" 944 | } 945 | ], 946 | "payable": false, 947 | "stateMutability": "view", 948 | "type": "function" 949 | }, 950 | { 951 | "constant": true, 952 | "inputs": [], 953 | "name": "getColor", 954 | "outputs": [ 955 | { 956 | "internalType": "bytes32", 957 | "name": "", 958 | "type": "bytes32" 959 | } 960 | ], 961 | "payable": false, 962 | "stateMutability": "view", 963 | "type": "function" 964 | }, 965 | { 966 | "constant": true, 967 | "inputs": [], 968 | "name": "getController", 969 | "outputs": [ 970 | { 971 | "internalType": "address", 972 | "name": "", 973 | "type": "address" 974 | } 975 | ], 976 | "payable": false, 977 | "stateMutability": "view", 978 | "type": "function" 979 | }, 980 | { 981 | "constant": true, 982 | "inputs": [], 983 | "name": "getCurrentTokens", 984 | "outputs": [ 985 | { 986 | "internalType": "address[]", 987 | "name": "tokens", 988 | "type": "address[]" 989 | } 990 | ], 991 | "payable": false, 992 | "stateMutability": "view", 993 | "type": "function" 994 | }, 995 | { 996 | "constant": true, 997 | "inputs": [ 998 | { 999 | "internalType": "address", 1000 | "name": "token", 1001 | "type": "address" 1002 | } 1003 | ], 1004 | "name": "getDenormalizedWeight", 1005 | "outputs": [ 1006 | { 1007 | "internalType": "uint256", 1008 | "name": "", 1009 | "type": "uint256" 1010 | } 1011 | ], 1012 | "payable": false, 1013 | "stateMutability": "view", 1014 | "type": "function" 1015 | }, 1016 | { 1017 | "constant": true, 1018 | "inputs": [], 1019 | "name": "getFinalTokens", 1020 | "outputs": [ 1021 | { 1022 | "internalType": "address[]", 1023 | "name": "tokens", 1024 | "type": "address[]" 1025 | } 1026 | ], 1027 | "payable": false, 1028 | "stateMutability": "view", 1029 | "type": "function" 1030 | }, 1031 | { 1032 | "constant": true, 1033 | "inputs": [ 1034 | { 1035 | "internalType": "address", 1036 | "name": "token", 1037 | "type": "address" 1038 | } 1039 | ], 1040 | "name": "getNormalizedWeight", 1041 | "outputs": [ 1042 | { 1043 | "internalType": "uint256", 1044 | "name": "", 1045 | "type": "uint256" 1046 | } 1047 | ], 1048 | "payable": false, 1049 | "stateMutability": "view", 1050 | "type": "function" 1051 | }, 1052 | { 1053 | "constant": true, 1054 | "inputs": [], 1055 | "name": "getNumTokens", 1056 | "outputs": [ 1057 | { 1058 | "internalType": "uint256", 1059 | "name": "", 1060 | "type": "uint256" 1061 | } 1062 | ], 1063 | "payable": false, 1064 | "stateMutability": "view", 1065 | "type": "function" 1066 | }, 1067 | { 1068 | "constant": true, 1069 | "inputs": [ 1070 | { 1071 | "internalType": "address", 1072 | "name": "tokenIn", 1073 | "type": "address" 1074 | }, 1075 | { 1076 | "internalType": "address", 1077 | "name": "tokenOut", 1078 | "type": "address" 1079 | } 1080 | ], 1081 | "name": "getSpotPrice", 1082 | "outputs": [ 1083 | { 1084 | "internalType": "uint256", 1085 | "name": "spotPrice", 1086 | "type": "uint256" 1087 | } 1088 | ], 1089 | "payable": false, 1090 | "stateMutability": "view", 1091 | "type": "function" 1092 | }, 1093 | { 1094 | "constant": true, 1095 | "inputs": [ 1096 | { 1097 | "internalType": "address", 1098 | "name": "tokenIn", 1099 | "type": "address" 1100 | }, 1101 | { 1102 | "internalType": "address", 1103 | "name": "tokenOut", 1104 | "type": "address" 1105 | } 1106 | ], 1107 | "name": "getSpotPriceSansFee", 1108 | "outputs": [ 1109 | { 1110 | "internalType": "uint256", 1111 | "name": "spotPrice", 1112 | "type": "uint256" 1113 | } 1114 | ], 1115 | "payable": false, 1116 | "stateMutability": "view", 1117 | "type": "function" 1118 | }, 1119 | { 1120 | "constant": true, 1121 | "inputs": [], 1122 | "name": "getSwapFee", 1123 | "outputs": [ 1124 | { 1125 | "internalType": "uint256", 1126 | "name": "", 1127 | "type": "uint256" 1128 | } 1129 | ], 1130 | "payable": false, 1131 | "stateMutability": "view", 1132 | "type": "function" 1133 | }, 1134 | { 1135 | "constant": true, 1136 | "inputs": [], 1137 | "name": "getTotalDenormalizedWeight", 1138 | "outputs": [ 1139 | { 1140 | "internalType": "uint256", 1141 | "name": "", 1142 | "type": "uint256" 1143 | } 1144 | ], 1145 | "payable": false, 1146 | "stateMutability": "view", 1147 | "type": "function" 1148 | }, 1149 | { 1150 | "constant": false, 1151 | "inputs": [ 1152 | { 1153 | "internalType": "address", 1154 | "name": "token", 1155 | "type": "address" 1156 | } 1157 | ], 1158 | "name": "gulp", 1159 | "outputs": [], 1160 | "payable": false, 1161 | "stateMutability": "nonpayable", 1162 | "type": "function" 1163 | }, 1164 | { 1165 | "constant": false, 1166 | "inputs": [ 1167 | { 1168 | "internalType": "address", 1169 | "name": "dst", 1170 | "type": "address" 1171 | }, 1172 | { 1173 | "internalType": "uint256", 1174 | "name": "amt", 1175 | "type": "uint256" 1176 | } 1177 | ], 1178 | "name": "increaseApproval", 1179 | "outputs": [ 1180 | { 1181 | "internalType": "bool", 1182 | "name": "", 1183 | "type": "bool" 1184 | } 1185 | ], 1186 | "payable": false, 1187 | "stateMutability": "nonpayable", 1188 | "type": "function" 1189 | }, 1190 | { 1191 | "constant": true, 1192 | "inputs": [ 1193 | { 1194 | "internalType": "address", 1195 | "name": "t", 1196 | "type": "address" 1197 | } 1198 | ], 1199 | "name": "isBound", 1200 | "outputs": [ 1201 | { 1202 | "internalType": "bool", 1203 | "name": "", 1204 | "type": "bool" 1205 | } 1206 | ], 1207 | "payable": false, 1208 | "stateMutability": "view", 1209 | "type": "function" 1210 | }, 1211 | { 1212 | "constant": true, 1213 | "inputs": [], 1214 | "name": "isFinalized", 1215 | "outputs": [ 1216 | { 1217 | "internalType": "bool", 1218 | "name": "", 1219 | "type": "bool" 1220 | } 1221 | ], 1222 | "payable": false, 1223 | "stateMutability": "view", 1224 | "type": "function" 1225 | }, 1226 | { 1227 | "constant": true, 1228 | "inputs": [], 1229 | "name": "isPublicSwap", 1230 | "outputs": [ 1231 | { 1232 | "internalType": "bool", 1233 | "name": "", 1234 | "type": "bool" 1235 | } 1236 | ], 1237 | "payable": false, 1238 | "stateMutability": "view", 1239 | "type": "function" 1240 | }, 1241 | { 1242 | "constant": false, 1243 | "inputs": [ 1244 | { 1245 | "internalType": "uint256", 1246 | "name": "poolAmountOut", 1247 | "type": "uint256" 1248 | }, 1249 | { 1250 | "internalType": "uint256[]", 1251 | "name": "maxAmountsIn", 1252 | "type": "uint256[]" 1253 | } 1254 | ], 1255 | "name": "joinPool", 1256 | "outputs": [], 1257 | "payable": false, 1258 | "stateMutability": "nonpayable", 1259 | "type": "function" 1260 | }, 1261 | { 1262 | "constant": false, 1263 | "inputs": [ 1264 | { 1265 | "internalType": "address", 1266 | "name": "tokenIn", 1267 | "type": "address" 1268 | }, 1269 | { 1270 | "internalType": "uint256", 1271 | "name": "tokenAmountIn", 1272 | "type": "uint256" 1273 | }, 1274 | { 1275 | "internalType": "uint256", 1276 | "name": "minPoolAmountOut", 1277 | "type": "uint256" 1278 | } 1279 | ], 1280 | "name": "joinswapExternAmountIn", 1281 | "outputs": [ 1282 | { 1283 | "internalType": "uint256", 1284 | "name": "poolAmountOut", 1285 | "type": "uint256" 1286 | } 1287 | ], 1288 | "payable": false, 1289 | "stateMutability": "nonpayable", 1290 | "type": "function" 1291 | }, 1292 | { 1293 | "constant": false, 1294 | "inputs": [ 1295 | { 1296 | "internalType": "address", 1297 | "name": "tokenIn", 1298 | "type": "address" 1299 | }, 1300 | { 1301 | "internalType": "uint256", 1302 | "name": "poolAmountOut", 1303 | "type": "uint256" 1304 | }, 1305 | { 1306 | "internalType": "uint256", 1307 | "name": "maxAmountIn", 1308 | "type": "uint256" 1309 | } 1310 | ], 1311 | "name": "joinswapPoolAmountOut", 1312 | "outputs": [ 1313 | { 1314 | "internalType": "uint256", 1315 | "name": "tokenAmountIn", 1316 | "type": "uint256" 1317 | } 1318 | ], 1319 | "payable": false, 1320 | "stateMutability": "nonpayable", 1321 | "type": "function" 1322 | }, 1323 | { 1324 | "constant": true, 1325 | "inputs": [], 1326 | "name": "name", 1327 | "outputs": [ 1328 | { 1329 | "internalType": "string", 1330 | "name": "", 1331 | "type": "string" 1332 | } 1333 | ], 1334 | "payable": false, 1335 | "stateMutability": "view", 1336 | "type": "function" 1337 | }, 1338 | { 1339 | "constant": false, 1340 | "inputs": [ 1341 | { 1342 | "internalType": "address", 1343 | "name": "token", 1344 | "type": "address" 1345 | }, 1346 | { 1347 | "internalType": "uint256", 1348 | "name": "balance", 1349 | "type": "uint256" 1350 | }, 1351 | { 1352 | "internalType": "uint256", 1353 | "name": "denorm", 1354 | "type": "uint256" 1355 | } 1356 | ], 1357 | "name": "rebind", 1358 | "outputs": [], 1359 | "payable": false, 1360 | "stateMutability": "nonpayable", 1361 | "type": "function" 1362 | }, 1363 | { 1364 | "constant": false, 1365 | "inputs": [ 1366 | { 1367 | "internalType": "address", 1368 | "name": "manager", 1369 | "type": "address" 1370 | } 1371 | ], 1372 | "name": "setController", 1373 | "outputs": [], 1374 | "payable": false, 1375 | "stateMutability": "nonpayable", 1376 | "type": "function" 1377 | }, 1378 | { 1379 | "constant": false, 1380 | "inputs": [ 1381 | { 1382 | "internalType": "bool", 1383 | "name": "public_", 1384 | "type": "bool" 1385 | } 1386 | ], 1387 | "name": "setPublicSwap", 1388 | "outputs": [], 1389 | "payable": false, 1390 | "stateMutability": "nonpayable", 1391 | "type": "function" 1392 | }, 1393 | { 1394 | "constant": false, 1395 | "inputs": [ 1396 | { 1397 | "internalType": "uint256", 1398 | "name": "swapFee", 1399 | "type": "uint256" 1400 | } 1401 | ], 1402 | "name": "setSwapFee", 1403 | "outputs": [], 1404 | "payable": false, 1405 | "stateMutability": "nonpayable", 1406 | "type": "function" 1407 | }, 1408 | { 1409 | "constant": false, 1410 | "inputs": [ 1411 | { 1412 | "internalType": "address", 1413 | "name": "tokenIn", 1414 | "type": "address" 1415 | }, 1416 | { 1417 | "internalType": "uint256", 1418 | "name": "tokenAmountIn", 1419 | "type": "uint256" 1420 | }, 1421 | { 1422 | "internalType": "address", 1423 | "name": "tokenOut", 1424 | "type": "address" 1425 | }, 1426 | { 1427 | "internalType": "uint256", 1428 | "name": "minAmountOut", 1429 | "type": "uint256" 1430 | }, 1431 | { 1432 | "internalType": "uint256", 1433 | "name": "maxPrice", 1434 | "type": "uint256" 1435 | } 1436 | ], 1437 | "name": "swapExactAmountIn", 1438 | "outputs": [ 1439 | { 1440 | "internalType": "uint256", 1441 | "name": "tokenAmountOut", 1442 | "type": "uint256" 1443 | }, 1444 | { 1445 | "internalType": "uint256", 1446 | "name": "spotPriceAfter", 1447 | "type": "uint256" 1448 | } 1449 | ], 1450 | "payable": false, 1451 | "stateMutability": "nonpayable", 1452 | "type": "function" 1453 | }, 1454 | { 1455 | "constant": false, 1456 | "inputs": [ 1457 | { 1458 | "internalType": "address", 1459 | "name": "tokenIn", 1460 | "type": "address" 1461 | }, 1462 | { 1463 | "internalType": "uint256", 1464 | "name": "maxAmountIn", 1465 | "type": "uint256" 1466 | }, 1467 | { 1468 | "internalType": "address", 1469 | "name": "tokenOut", 1470 | "type": "address" 1471 | }, 1472 | { 1473 | "internalType": "uint256", 1474 | "name": "tokenAmountOut", 1475 | "type": "uint256" 1476 | }, 1477 | { 1478 | "internalType": "uint256", 1479 | "name": "maxPrice", 1480 | "type": "uint256" 1481 | } 1482 | ], 1483 | "name": "swapExactAmountOut", 1484 | "outputs": [ 1485 | { 1486 | "internalType": "uint256", 1487 | "name": "tokenAmountIn", 1488 | "type": "uint256" 1489 | }, 1490 | { 1491 | "internalType": "uint256", 1492 | "name": "spotPriceAfter", 1493 | "type": "uint256" 1494 | } 1495 | ], 1496 | "payable": false, 1497 | "stateMutability": "nonpayable", 1498 | "type": "function" 1499 | }, 1500 | { 1501 | "constant": true, 1502 | "inputs": [], 1503 | "name": "symbol", 1504 | "outputs": [ 1505 | { 1506 | "internalType": "string", 1507 | "name": "", 1508 | "type": "string" 1509 | } 1510 | ], 1511 | "payable": false, 1512 | "stateMutability": "view", 1513 | "type": "function" 1514 | }, 1515 | { 1516 | "constant": true, 1517 | "inputs": [], 1518 | "name": "totalSupply", 1519 | "outputs": [ 1520 | { 1521 | "internalType": "uint256", 1522 | "name": "", 1523 | "type": "uint256" 1524 | } 1525 | ], 1526 | "payable": false, 1527 | "stateMutability": "view", 1528 | "type": "function" 1529 | }, 1530 | { 1531 | "constant": false, 1532 | "inputs": [ 1533 | { 1534 | "internalType": "address", 1535 | "name": "dst", 1536 | "type": "address" 1537 | }, 1538 | { 1539 | "internalType": "uint256", 1540 | "name": "amt", 1541 | "type": "uint256" 1542 | } 1543 | ], 1544 | "name": "transfer", 1545 | "outputs": [ 1546 | { 1547 | "internalType": "bool", 1548 | "name": "", 1549 | "type": "bool" 1550 | } 1551 | ], 1552 | "payable": false, 1553 | "stateMutability": "nonpayable", 1554 | "type": "function" 1555 | }, 1556 | { 1557 | "constant": false, 1558 | "inputs": [ 1559 | { 1560 | "internalType": "address", 1561 | "name": "src", 1562 | "type": "address" 1563 | }, 1564 | { 1565 | "internalType": "address", 1566 | "name": "dst", 1567 | "type": "address" 1568 | }, 1569 | { 1570 | "internalType": "uint256", 1571 | "name": "amt", 1572 | "type": "uint256" 1573 | } 1574 | ], 1575 | "name": "transferFrom", 1576 | "outputs": [ 1577 | { 1578 | "internalType": "bool", 1579 | "name": "", 1580 | "type": "bool" 1581 | } 1582 | ], 1583 | "payable": false, 1584 | "stateMutability": "nonpayable", 1585 | "type": "function" 1586 | }, 1587 | { 1588 | "constant": false, 1589 | "inputs": [ 1590 | { 1591 | "internalType": "address", 1592 | "name": "token", 1593 | "type": "address" 1594 | } 1595 | ], 1596 | "name": "unbind", 1597 | "outputs": [], 1598 | "payable": false, 1599 | "stateMutability": "nonpayable", 1600 | "type": "function" 1601 | }] 1602 | } -------------------------------------------------------------------------------- /abis/BToken.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "anonymous": false, 4 | "inputs": [ 5 | { 6 | "indexed": true, 7 | "internalType": "address", 8 | "name": "src", 9 | "type": "address" 10 | }, 11 | { 12 | "indexed": true, 13 | "internalType": "address", 14 | "name": "dst", 15 | "type": "address" 16 | }, 17 | { 18 | "indexed": false, 19 | "internalType": "uint256", 20 | "name": "amt", 21 | "type": "uint256" 22 | } 23 | ], 24 | "name": "Approval", 25 | "type": "event" 26 | }, 27 | { 28 | "anonymous": false, 29 | "inputs": [ 30 | { 31 | "indexed": true, 32 | "internalType": "address", 33 | "name": "src", 34 | "type": "address" 35 | }, 36 | { 37 | "indexed": true, 38 | "internalType": "address", 39 | "name": "dst", 40 | "type": "address" 41 | }, 42 | { 43 | "indexed": false, 44 | "internalType": "uint256", 45 | "name": "amt", 46 | "type": "uint256" 47 | } 48 | ], 49 | "name": "Transfer", 50 | "type": "event" 51 | }, 52 | { 53 | "constant": true, 54 | "inputs": [], 55 | "name": "BONE", 56 | "outputs": [ 57 | { 58 | "internalType": "uint256", 59 | "name": "", 60 | "type": "uint256" 61 | } 62 | ], 63 | "payable": false, 64 | "stateMutability": "view", 65 | "type": "function" 66 | }, 67 | { 68 | "constant": true, 69 | "inputs": [], 70 | "name": "BPOW_PRECISION", 71 | "outputs": [ 72 | { 73 | "internalType": "uint256", 74 | "name": "", 75 | "type": "uint256" 76 | } 77 | ], 78 | "payable": false, 79 | "stateMutability": "view", 80 | "type": "function" 81 | }, 82 | { 83 | "constant": true, 84 | "inputs": [], 85 | "name": "EXIT_FEE", 86 | "outputs": [ 87 | { 88 | "internalType": "uint256", 89 | "name": "", 90 | "type": "uint256" 91 | } 92 | ], 93 | "payable": false, 94 | "stateMutability": "view", 95 | "type": "function" 96 | }, 97 | { 98 | "constant": true, 99 | "inputs": [], 100 | "name": "INIT_POOL_SUPPLY", 101 | "outputs": [ 102 | { 103 | "internalType": "uint256", 104 | "name": "", 105 | "type": "uint256" 106 | } 107 | ], 108 | "payable": false, 109 | "stateMutability": "view", 110 | "type": "function" 111 | }, 112 | { 113 | "constant": true, 114 | "inputs": [], 115 | "name": "MAX_BOUND_TOKENS", 116 | "outputs": [ 117 | { 118 | "internalType": "uint256", 119 | "name": "", 120 | "type": "uint256" 121 | } 122 | ], 123 | "payable": false, 124 | "stateMutability": "view", 125 | "type": "function" 126 | }, 127 | { 128 | "constant": true, 129 | "inputs": [], 130 | "name": "MAX_BPOW_BASE", 131 | "outputs": [ 132 | { 133 | "internalType": "uint256", 134 | "name": "", 135 | "type": "uint256" 136 | } 137 | ], 138 | "payable": false, 139 | "stateMutability": "view", 140 | "type": "function" 141 | }, 142 | { 143 | "constant": true, 144 | "inputs": [], 145 | "name": "MAX_FEE", 146 | "outputs": [ 147 | { 148 | "internalType": "uint256", 149 | "name": "", 150 | "type": "uint256" 151 | } 152 | ], 153 | "payable": false, 154 | "stateMutability": "view", 155 | "type": "function" 156 | }, 157 | { 158 | "constant": true, 159 | "inputs": [], 160 | "name": "MAX_TOTAL_WEIGHT", 161 | "outputs": [ 162 | { 163 | "internalType": "uint256", 164 | "name": "", 165 | "type": "uint256" 166 | } 167 | ], 168 | "payable": false, 169 | "stateMutability": "view", 170 | "type": "function" 171 | }, 172 | { 173 | "constant": true, 174 | "inputs": [], 175 | "name": "MAX_WEIGHT", 176 | "outputs": [ 177 | { 178 | "internalType": "uint256", 179 | "name": "", 180 | "type": "uint256" 181 | } 182 | ], 183 | "payable": false, 184 | "stateMutability": "view", 185 | "type": "function" 186 | }, 187 | { 188 | "constant": true, 189 | "inputs": [], 190 | "name": "MIN_BALANCE", 191 | "outputs": [ 192 | { 193 | "internalType": "uint256", 194 | "name": "", 195 | "type": "uint256" 196 | } 197 | ], 198 | "payable": false, 199 | "stateMutability": "view", 200 | "type": "function" 201 | }, 202 | { 203 | "constant": true, 204 | "inputs": [], 205 | "name": "MIN_BOUND_TOKENS", 206 | "outputs": [ 207 | { 208 | "internalType": "uint256", 209 | "name": "", 210 | "type": "uint256" 211 | } 212 | ], 213 | "payable": false, 214 | "stateMutability": "view", 215 | "type": "function" 216 | }, 217 | { 218 | "constant": true, 219 | "inputs": [], 220 | "name": "MIN_BPOW_BASE", 221 | "outputs": [ 222 | { 223 | "internalType": "uint256", 224 | "name": "", 225 | "type": "uint256" 226 | } 227 | ], 228 | "payable": false, 229 | "stateMutability": "view", 230 | "type": "function" 231 | }, 232 | { 233 | "constant": true, 234 | "inputs": [], 235 | "name": "MIN_FEE", 236 | "outputs": [ 237 | { 238 | "internalType": "uint256", 239 | "name": "", 240 | "type": "uint256" 241 | } 242 | ], 243 | "payable": false, 244 | "stateMutability": "view", 245 | "type": "function" 246 | }, 247 | { 248 | "constant": true, 249 | "inputs": [], 250 | "name": "MIN_WEIGHT", 251 | "outputs": [ 252 | { 253 | "internalType": "uint256", 254 | "name": "", 255 | "type": "uint256" 256 | } 257 | ], 258 | "payable": false, 259 | "stateMutability": "view", 260 | "type": "function" 261 | }, 262 | { 263 | "constant": true, 264 | "inputs": [ 265 | { 266 | "internalType": "address", 267 | "name": "src", 268 | "type": "address" 269 | }, 270 | { 271 | "internalType": "address", 272 | "name": "dst", 273 | "type": "address" 274 | } 275 | ], 276 | "name": "allowance", 277 | "outputs": [ 278 | { 279 | "internalType": "uint256", 280 | "name": "", 281 | "type": "uint256" 282 | } 283 | ], 284 | "payable": false, 285 | "stateMutability": "view", 286 | "type": "function" 287 | }, 288 | { 289 | "constant": false, 290 | "inputs": [ 291 | { 292 | "internalType": "address", 293 | "name": "dst", 294 | "type": "address" 295 | }, 296 | { 297 | "internalType": "uint256", 298 | "name": "amt", 299 | "type": "uint256" 300 | } 301 | ], 302 | "name": "approve", 303 | "outputs": [ 304 | { 305 | "internalType": "bool", 306 | "name": "", 307 | "type": "bool" 308 | } 309 | ], 310 | "payable": false, 311 | "stateMutability": "nonpayable", 312 | "type": "function" 313 | }, 314 | { 315 | "constant": true, 316 | "inputs": [ 317 | { 318 | "internalType": "address", 319 | "name": "whom", 320 | "type": "address" 321 | } 322 | ], 323 | "name": "balanceOf", 324 | "outputs": [ 325 | { 326 | "internalType": "uint256", 327 | "name": "", 328 | "type": "uint256" 329 | } 330 | ], 331 | "payable": false, 332 | "stateMutability": "view", 333 | "type": "function" 334 | }, 335 | { 336 | "constant": true, 337 | "inputs": [], 338 | "name": "decimals", 339 | "outputs": [ 340 | { 341 | "internalType": "uint8", 342 | "name": "", 343 | "type": "uint8" 344 | } 345 | ], 346 | "payable": false, 347 | "stateMutability": "view", 348 | "type": "function" 349 | }, 350 | { 351 | "constant": false, 352 | "inputs": [ 353 | { 354 | "internalType": "address", 355 | "name": "dst", 356 | "type": "address" 357 | }, 358 | { 359 | "internalType": "uint256", 360 | "name": "amt", 361 | "type": "uint256" 362 | } 363 | ], 364 | "name": "decreaseApproval", 365 | "outputs": [ 366 | { 367 | "internalType": "bool", 368 | "name": "", 369 | "type": "bool" 370 | } 371 | ], 372 | "payable": false, 373 | "stateMutability": "nonpayable", 374 | "type": "function" 375 | }, 376 | { 377 | "constant": true, 378 | "inputs": [], 379 | "name": "getColor", 380 | "outputs": [ 381 | { 382 | "internalType": "bytes32", 383 | "name": "", 384 | "type": "bytes32" 385 | } 386 | ], 387 | "payable": false, 388 | "stateMutability": "view", 389 | "type": "function" 390 | }, 391 | { 392 | "constant": false, 393 | "inputs": [ 394 | { 395 | "internalType": "address", 396 | "name": "dst", 397 | "type": "address" 398 | }, 399 | { 400 | "internalType": "uint256", 401 | "name": "amt", 402 | "type": "uint256" 403 | } 404 | ], 405 | "name": "increaseApproval", 406 | "outputs": [ 407 | { 408 | "internalType": "bool", 409 | "name": "", 410 | "type": "bool" 411 | } 412 | ], 413 | "payable": false, 414 | "stateMutability": "nonpayable", 415 | "type": "function" 416 | }, 417 | { 418 | "constant": true, 419 | "inputs": [], 420 | "name": "name", 421 | "outputs": [ 422 | { 423 | "internalType": "string", 424 | "name": "", 425 | "type": "string" 426 | } 427 | ], 428 | "payable": false, 429 | "stateMutability": "view", 430 | "type": "function" 431 | }, 432 | { 433 | "constant": true, 434 | "inputs": [], 435 | "name": "symbol", 436 | "outputs": [ 437 | { 438 | "internalType": "string", 439 | "name": "", 440 | "type": "string" 441 | } 442 | ], 443 | "payable": false, 444 | "stateMutability": "view", 445 | "type": "function" 446 | }, 447 | { 448 | "constant": true, 449 | "inputs": [], 450 | "name": "totalSupply", 451 | "outputs": [ 452 | { 453 | "internalType": "uint256", 454 | "name": "", 455 | "type": "uint256" 456 | } 457 | ], 458 | "payable": false, 459 | "stateMutability": "view", 460 | "type": "function" 461 | }, 462 | { 463 | "constant": false, 464 | "inputs": [ 465 | { 466 | "internalType": "address", 467 | "name": "dst", 468 | "type": "address" 469 | }, 470 | { 471 | "internalType": "uint256", 472 | "name": "amt", 473 | "type": "uint256" 474 | } 475 | ], 476 | "name": "transfer", 477 | "outputs": [ 478 | { 479 | "internalType": "bool", 480 | "name": "", 481 | "type": "bool" 482 | } 483 | ], 484 | "payable": false, 485 | "stateMutability": "nonpayable", 486 | "type": "function" 487 | }, 488 | { 489 | "constant": false, 490 | "inputs": [ 491 | { 492 | "internalType": "address", 493 | "name": "src", 494 | "type": "address" 495 | }, 496 | { 497 | "internalType": "address", 498 | "name": "dst", 499 | "type": "address" 500 | }, 501 | { 502 | "internalType": "uint256", 503 | "name": "amt", 504 | "type": "uint256" 505 | } 506 | ], 507 | "name": "transferFrom", 508 | "outputs": [ 509 | { 510 | "internalType": "bool", 511 | "name": "", 512 | "type": "bool" 513 | } 514 | ], 515 | "payable": false, 516 | "stateMutability": "nonpayable", 517 | "type": "function" 518 | } 519 | ] 520 | -------------------------------------------------------------------------------- /abis/BTokenBytes32.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "anonymous": false, 4 | "inputs": [ 5 | { 6 | "indexed": true, 7 | "internalType": "address", 8 | "name": "src", 9 | "type": "address" 10 | }, 11 | { 12 | "indexed": true, 13 | "internalType": "address", 14 | "name": "dst", 15 | "type": "address" 16 | }, 17 | { 18 | "indexed": false, 19 | "internalType": "uint256", 20 | "name": "amt", 21 | "type": "uint256" 22 | } 23 | ], 24 | "name": "Approval", 25 | "type": "event" 26 | }, 27 | { 28 | "anonymous": false, 29 | "inputs": [ 30 | { 31 | "indexed": true, 32 | "internalType": "address", 33 | "name": "src", 34 | "type": "address" 35 | }, 36 | { 37 | "indexed": true, 38 | "internalType": "address", 39 | "name": "dst", 40 | "type": "address" 41 | }, 42 | { 43 | "indexed": false, 44 | "internalType": "uint256", 45 | "name": "amt", 46 | "type": "uint256" 47 | } 48 | ], 49 | "name": "Transfer", 50 | "type": "event" 51 | }, 52 | { 53 | "constant": true, 54 | "inputs": [], 55 | "name": "BONE", 56 | "outputs": [ 57 | { 58 | "internalType": "uint256", 59 | "name": "", 60 | "type": "uint256" 61 | } 62 | ], 63 | "payable": false, 64 | "stateMutability": "view", 65 | "type": "function" 66 | }, 67 | { 68 | "constant": true, 69 | "inputs": [], 70 | "name": "BPOW_PRECISION", 71 | "outputs": [ 72 | { 73 | "internalType": "uint256", 74 | "name": "", 75 | "type": "uint256" 76 | } 77 | ], 78 | "payable": false, 79 | "stateMutability": "view", 80 | "type": "function" 81 | }, 82 | { 83 | "constant": true, 84 | "inputs": [], 85 | "name": "EXIT_FEE", 86 | "outputs": [ 87 | { 88 | "internalType": "uint256", 89 | "name": "", 90 | "type": "uint256" 91 | } 92 | ], 93 | "payable": false, 94 | "stateMutability": "view", 95 | "type": "function" 96 | }, 97 | { 98 | "constant": true, 99 | "inputs": [], 100 | "name": "INIT_POOL_SUPPLY", 101 | "outputs": [ 102 | { 103 | "internalType": "uint256", 104 | "name": "", 105 | "type": "uint256" 106 | } 107 | ], 108 | "payable": false, 109 | "stateMutability": "view", 110 | "type": "function" 111 | }, 112 | { 113 | "constant": true, 114 | "inputs": [], 115 | "name": "MAX_BOUND_TOKENS", 116 | "outputs": [ 117 | { 118 | "internalType": "uint256", 119 | "name": "", 120 | "type": "uint256" 121 | } 122 | ], 123 | "payable": false, 124 | "stateMutability": "view", 125 | "type": "function" 126 | }, 127 | { 128 | "constant": true, 129 | "inputs": [], 130 | "name": "MAX_BPOW_BASE", 131 | "outputs": [ 132 | { 133 | "internalType": "uint256", 134 | "name": "", 135 | "type": "uint256" 136 | } 137 | ], 138 | "payable": false, 139 | "stateMutability": "view", 140 | "type": "function" 141 | }, 142 | { 143 | "constant": true, 144 | "inputs": [], 145 | "name": "MAX_FEE", 146 | "outputs": [ 147 | { 148 | "internalType": "uint256", 149 | "name": "", 150 | "type": "uint256" 151 | } 152 | ], 153 | "payable": false, 154 | "stateMutability": "view", 155 | "type": "function" 156 | }, 157 | { 158 | "constant": true, 159 | "inputs": [], 160 | "name": "MAX_TOTAL_WEIGHT", 161 | "outputs": [ 162 | { 163 | "internalType": "uint256", 164 | "name": "", 165 | "type": "uint256" 166 | } 167 | ], 168 | "payable": false, 169 | "stateMutability": "view", 170 | "type": "function" 171 | }, 172 | { 173 | "constant": true, 174 | "inputs": [], 175 | "name": "MAX_WEIGHT", 176 | "outputs": [ 177 | { 178 | "internalType": "uint256", 179 | "name": "", 180 | "type": "uint256" 181 | } 182 | ], 183 | "payable": false, 184 | "stateMutability": "view", 185 | "type": "function" 186 | }, 187 | { 188 | "constant": true, 189 | "inputs": [], 190 | "name": "MIN_BALANCE", 191 | "outputs": [ 192 | { 193 | "internalType": "uint256", 194 | "name": "", 195 | "type": "uint256" 196 | } 197 | ], 198 | "payable": false, 199 | "stateMutability": "view", 200 | "type": "function" 201 | }, 202 | { 203 | "constant": true, 204 | "inputs": [], 205 | "name": "MIN_BOUND_TOKENS", 206 | "outputs": [ 207 | { 208 | "internalType": "uint256", 209 | "name": "", 210 | "type": "uint256" 211 | } 212 | ], 213 | "payable": false, 214 | "stateMutability": "view", 215 | "type": "function" 216 | }, 217 | { 218 | "constant": true, 219 | "inputs": [], 220 | "name": "MIN_BPOW_BASE", 221 | "outputs": [ 222 | { 223 | "internalType": "uint256", 224 | "name": "", 225 | "type": "uint256" 226 | } 227 | ], 228 | "payable": false, 229 | "stateMutability": "view", 230 | "type": "function" 231 | }, 232 | { 233 | "constant": true, 234 | "inputs": [], 235 | "name": "MIN_FEE", 236 | "outputs": [ 237 | { 238 | "internalType": "uint256", 239 | "name": "", 240 | "type": "uint256" 241 | } 242 | ], 243 | "payable": false, 244 | "stateMutability": "view", 245 | "type": "function" 246 | }, 247 | { 248 | "constant": true, 249 | "inputs": [], 250 | "name": "MIN_WEIGHT", 251 | "outputs": [ 252 | { 253 | "internalType": "uint256", 254 | "name": "", 255 | "type": "uint256" 256 | } 257 | ], 258 | "payable": false, 259 | "stateMutability": "view", 260 | "type": "function" 261 | }, 262 | { 263 | "constant": true, 264 | "inputs": [ 265 | { 266 | "internalType": "address", 267 | "name": "src", 268 | "type": "address" 269 | }, 270 | { 271 | "internalType": "address", 272 | "name": "dst", 273 | "type": "address" 274 | } 275 | ], 276 | "name": "allowance", 277 | "outputs": [ 278 | { 279 | "internalType": "uint256", 280 | "name": "", 281 | "type": "uint256" 282 | } 283 | ], 284 | "payable": false, 285 | "stateMutability": "view", 286 | "type": "function" 287 | }, 288 | { 289 | "constant": false, 290 | "inputs": [ 291 | { 292 | "internalType": "address", 293 | "name": "dst", 294 | "type": "address" 295 | }, 296 | { 297 | "internalType": "uint256", 298 | "name": "amt", 299 | "type": "uint256" 300 | } 301 | ], 302 | "name": "approve", 303 | "outputs": [ 304 | { 305 | "internalType": "bool", 306 | "name": "", 307 | "type": "bool" 308 | } 309 | ], 310 | "payable": false, 311 | "stateMutability": "nonpayable", 312 | "type": "function" 313 | }, 314 | { 315 | "constant": true, 316 | "inputs": [ 317 | { 318 | "internalType": "address", 319 | "name": "whom", 320 | "type": "address" 321 | } 322 | ], 323 | "name": "balanceOf", 324 | "outputs": [ 325 | { 326 | "internalType": "uint256", 327 | "name": "", 328 | "type": "uint256" 329 | } 330 | ], 331 | "payable": false, 332 | "stateMutability": "view", 333 | "type": "function" 334 | }, 335 | { 336 | "constant": true, 337 | "inputs": [], 338 | "name": "decimals", 339 | "outputs": [ 340 | { 341 | "internalType": "uint8", 342 | "name": "", 343 | "type": "uint8" 344 | } 345 | ], 346 | "payable": false, 347 | "stateMutability": "view", 348 | "type": "function" 349 | }, 350 | { 351 | "constant": false, 352 | "inputs": [ 353 | { 354 | "internalType": "address", 355 | "name": "dst", 356 | "type": "address" 357 | }, 358 | { 359 | "internalType": "uint256", 360 | "name": "amt", 361 | "type": "uint256" 362 | } 363 | ], 364 | "name": "decreaseApproval", 365 | "outputs": [ 366 | { 367 | "internalType": "bool", 368 | "name": "", 369 | "type": "bool" 370 | } 371 | ], 372 | "payable": false, 373 | "stateMutability": "nonpayable", 374 | "type": "function" 375 | }, 376 | { 377 | "constant": true, 378 | "inputs": [], 379 | "name": "getColor", 380 | "outputs": [ 381 | { 382 | "internalType": "bytes32", 383 | "name": "", 384 | "type": "bytes32" 385 | } 386 | ], 387 | "payable": false, 388 | "stateMutability": "view", 389 | "type": "function" 390 | }, 391 | { 392 | "constant": false, 393 | "inputs": [ 394 | { 395 | "internalType": "address", 396 | "name": "dst", 397 | "type": "address" 398 | }, 399 | { 400 | "internalType": "uint256", 401 | "name": "amt", 402 | "type": "uint256" 403 | } 404 | ], 405 | "name": "increaseApproval", 406 | "outputs": [ 407 | { 408 | "internalType": "bool", 409 | "name": "", 410 | "type": "bool" 411 | } 412 | ], 413 | "payable": false, 414 | "stateMutability": "nonpayable", 415 | "type": "function" 416 | }, 417 | { 418 | "constant": true, 419 | "inputs": [], 420 | "name": "name", 421 | "outputs": [ 422 | { 423 | "internalType": "bytes32", 424 | "name": "", 425 | "type": "bytes32" 426 | } 427 | ], 428 | "payable": false, 429 | "stateMutability": "view", 430 | "type": "function" 431 | }, 432 | { 433 | "constant": true, 434 | "inputs": [], 435 | "name": "symbol", 436 | "outputs": [ 437 | { 438 | "internalType": "bytes32", 439 | "name": "", 440 | "type": "bytes32" 441 | } 442 | ], 443 | "payable": false, 444 | "stateMutability": "view", 445 | "type": "function" 446 | }, 447 | { 448 | "constant": true, 449 | "inputs": [], 450 | "name": "totalSupply", 451 | "outputs": [ 452 | { 453 | "internalType": "uint256", 454 | "name": "", 455 | "type": "uint256" 456 | } 457 | ], 458 | "payable": false, 459 | "stateMutability": "view", 460 | "type": "function" 461 | }, 462 | { 463 | "constant": false, 464 | "inputs": [ 465 | { 466 | "internalType": "address", 467 | "name": "dst", 468 | "type": "address" 469 | }, 470 | { 471 | "internalType": "uint256", 472 | "name": "amt", 473 | "type": "uint256" 474 | } 475 | ], 476 | "name": "transfer", 477 | "outputs": [ 478 | { 479 | "internalType": "bool", 480 | "name": "", 481 | "type": "bool" 482 | } 483 | ], 484 | "payable": false, 485 | "stateMutability": "nonpayable", 486 | "type": "function" 487 | }, 488 | { 489 | "constant": false, 490 | "inputs": [ 491 | { 492 | "internalType": "address", 493 | "name": "src", 494 | "type": "address" 495 | }, 496 | { 497 | "internalType": "address", 498 | "name": "dst", 499 | "type": "address" 500 | }, 501 | { 502 | "internalType": "uint256", 503 | "name": "amt", 504 | "type": "uint256" 505 | } 506 | ], 507 | "name": "transferFrom", 508 | "outputs": [ 509 | { 510 | "internalType": "bool", 511 | "name": "", 512 | "type": "bool" 513 | } 514 | ], 515 | "payable": false, 516 | "stateMutability": "nonpayable", 517 | "type": "function" 518 | } 519 | ] 520 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "balancer", 3 | "version": "0.1.0", 4 | "scripts": { 5 | "create": "graph create balancer-labs/balancer-subgraph --node https://api.thegraph.com/deploy/", 6 | "create:local": "graph create balancer-labs/balancer-subgraph --node http://127.0.0.1:8020", 7 | "codegen": "graph codegen --output-dir src/types/", 8 | "build": "graph build", 9 | "deploy": "graph deploy balancer-labs/balancer --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", 10 | "deploy:beta": "graph deploy balancer-labs/balancer-beta --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", 11 | "deploy:kovan": "graph deploy balancer-labs/balancer-kovan subgraph.kovan.yaml --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", 12 | "deploy:rinkeby": "graph deploy balancer-labs/balancer-rinkeby subgraph.rinkeby.yaml --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", 13 | "deploy:ropsten": "graph deploy balancer-labs/balancer-ropsten subgraph.ropsten.yaml --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", 14 | "deploy:local": "graph deploy balancer-labs/balancer-subgraph subgraph.yaml --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020" 15 | }, 16 | "devDependencies": { 17 | "@graphprotocol/graph-cli": "^0.18.0", 18 | "@graphprotocol/graph-ts": "^0.18.1" 19 | }, 20 | "dependencies": { 21 | "babel-polyfill": "^6.26.0", 22 | "babel-register": "^6.26.0", 23 | "keytar": "^5.0.0", 24 | "truffle": "^5.1.0", 25 | "truffle-contract": "^4.0.5", 26 | "truffle-hdwallet-provider": "^1.0.4" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /schema.graphql: -------------------------------------------------------------------------------- 1 | type Balancer @entity { 2 | id: ID! 3 | color: String! # Bronze, Silver, Gold 4 | poolCount: Int! # Number of pools 5 | finalizedPoolCount: Int! # Number of finalized pools 6 | crpCount: Int! # Number of CRP 7 | pools: [Pool!] @derivedFrom(field: "factoryID") 8 | txCount: BigInt! # Number of txs 9 | totalLiquidity: BigDecimal! # All the pools liquidity value in USD 10 | totalSwapVolume: BigDecimal! # All the swap volume in USD 11 | totalSwapFee: BigDecimal! # All the swap fee in USD 12 | } 13 | 14 | type Pool @entity { 15 | id: ID! # Pool address 16 | controller: Bytes! # Controller address 17 | publicSwap: Boolean! # isPublicSwap 18 | finalized: Boolean! # isFinalized 19 | crp: Boolean! # Is configurable rights pool 20 | crpController: Bytes # CRP controller address 21 | symbol: String # Pool token symbol 22 | name: String # Pool token name 23 | rights: [String!]! # List of rights (for CRP) 24 | cap: BigInt # Maximum supply if any (for CRP) 25 | active: Boolean! # isActive 26 | swapFee: BigDecimal! # Swap Fees 27 | totalWeight: BigDecimal! 28 | totalShares: BigDecimal! # Total pool token shares 29 | totalSwapVolume: BigDecimal! # Total swap volume in USD 30 | totalSwapFee: BigDecimal! # Total swap fee in USD 31 | liquidity: BigDecimal! # Pool liquidity value in USD 32 | tokensList: [Bytes!]! # Temp workaround until graph supports filtering on derived field 33 | tokens: [PoolToken!] @derivedFrom(field: "poolId") 34 | shares: [PoolShare!] @derivedFrom(field: "poolId") 35 | createTime: Int! # Block time pool was created 36 | tokensCount: BigInt! # Number of tokens in the pool 37 | holdersCount: BigInt! # Number of addresses holding a positive balance of BPT 38 | joinsCount: BigInt! # liquidity has been added 39 | exitsCount: BigInt! # liquidity has been removed 40 | swapsCount: BigInt! 41 | factoryID: Balancer! 42 | tx: Bytes # Pool creation transaction id 43 | swaps: [Swap!] @derivedFrom(field: "poolAddress") 44 | } 45 | 46 | type PoolToken @entity { 47 | id: ID! # poolId + token address 48 | poolId: Pool! 49 | symbol: String 50 | name: String 51 | decimals: Int! 52 | address: String! 53 | balance: BigDecimal! 54 | denormWeight: BigDecimal! 55 | } 56 | 57 | type PoolShare @entity { 58 | id: ID! # poolId + userAddress 59 | userAddress: User! 60 | poolId: Pool! 61 | balance: BigDecimal! 62 | } 63 | 64 | type User @entity { 65 | id: ID! 66 | sharesOwned: [PoolShare!] @derivedFrom(field: "userAddress") 67 | txs: [Transaction!] @derivedFrom(field: "userAddress") 68 | swaps: [Swap!] @derivedFrom(field: "userAddress") 69 | } 70 | 71 | type Swap @entity { 72 | id: ID! # 73 | caller: Bytes! # 74 | tokenIn: Bytes! # 75 | tokenInSym: String! # 76 | tokenOut: Bytes! # 77 | tokenOutSym: String! # 78 | tokenAmountIn: BigDecimal! # 79 | tokenAmountOut: BigDecimal! # 80 | poolAddress: Pool 81 | userAddress: User # User address that initiates the swap 82 | value: BigDecimal! # Swap value in USD 83 | feeValue: BigDecimal! # Swap fee value in USD 84 | poolTotalSwapVolume: BigDecimal! # Total pool swap volume in USD 85 | poolTotalSwapFee: BigDecimal! # Total pool swap fee in USD 86 | poolLiquidity: BigDecimal! # Pool liquidity value in USD 87 | timestamp: Int! 88 | } 89 | 90 | type Transaction @entity { 91 | id: ID! # Log ID 92 | tx: Bytes! 93 | event: String 94 | block: Int! 95 | timestamp: Int! 96 | gasUsed: BigDecimal! 97 | gasPrice: BigDecimal! 98 | poolAddress: Pool 99 | userAddress: User 100 | action: SwapType 101 | sender: Bytes 102 | } 103 | 104 | type TokenPrice @entity { 105 | id: ID! 106 | symbol: String 107 | name: String 108 | decimals: Int! 109 | price: BigDecimal! 110 | poolLiquidity: BigDecimal! 111 | poolTokenId: String 112 | } 113 | 114 | enum SwapType { 115 | swapExactAmountIn, 116 | swapExactAmountOut, 117 | joinswapExternAmountIn, 118 | joinswapPoolAmountOut, 119 | exitswapPoolAmountIn, 120 | exitswapExternAmountOut 121 | } 122 | -------------------------------------------------------------------------------- /src/mappings/factory.ts: -------------------------------------------------------------------------------- 1 | import { Address, BigInt, BigDecimal } from '@graphprotocol/graph-ts' 2 | import { LOG_NEW_POOL } from '../types/Factory/Factory' 3 | import { Balancer, Pool } from '../types/schema' 4 | import { Pool as PoolContract, CrpController as CrpControllerContract } from '../types/templates' 5 | import { 6 | ZERO_BD, 7 | isCrp, 8 | getCrpController, 9 | getCrpSymbol, 10 | getCrpName, 11 | getCrpRights, 12 | getCrpCap 13 | } from './helpers' 14 | import { ConfigurableRightsPool } from '../types/Factory/ConfigurableRightsPool'; 15 | 16 | export function handleNewPool(event: LOG_NEW_POOL): void { 17 | let factory = Balancer.load('1') 18 | 19 | // if no factory yet, set up blank initial 20 | if (factory == null) { 21 | factory = new Balancer('1') 22 | factory.color = 'Bronze' 23 | factory.poolCount = 0 24 | factory.finalizedPoolCount = 0 25 | factory.crpCount = 0 26 | factory.txCount = BigInt.fromI32(0) 27 | factory.totalLiquidity = ZERO_BD 28 | factory.totalSwapVolume = ZERO_BD 29 | factory.totalSwapFee = ZERO_BD 30 | } 31 | 32 | let pool = new Pool(event.params.pool.toHexString()) 33 | pool.crp = isCrp(event.params.caller) 34 | pool.rights = [] 35 | if (pool.crp) { 36 | factory.crpCount += 1 37 | let crp = ConfigurableRightsPool.bind(event.params.caller) 38 | pool.symbol = getCrpSymbol(crp) 39 | pool.name = getCrpName(crp) 40 | pool.crpController = Address.fromString(getCrpController(crp)) 41 | pool.rights = getCrpRights(crp) 42 | pool.cap = getCrpCap(crp) 43 | 44 | // Listen for any future crpController changes. 45 | CrpControllerContract.create(event.params.caller) 46 | } 47 | pool.controller = event.params.caller 48 | pool.publicSwap = false 49 | pool.finalized = false 50 | pool.active = true 51 | pool.swapFee = BigDecimal.fromString('0.000001') 52 | pool.totalWeight = ZERO_BD 53 | pool.totalShares = ZERO_BD 54 | pool.totalSwapVolume = ZERO_BD 55 | pool.totalSwapFee = ZERO_BD 56 | pool.liquidity = ZERO_BD 57 | pool.createTime = event.block.timestamp.toI32() 58 | pool.tokensCount = BigInt.fromI32(0) 59 | pool.holdersCount = BigInt.fromI32(0) 60 | pool.joinsCount = BigInt.fromI32(0) 61 | pool.exitsCount = BigInt.fromI32(0) 62 | pool.swapsCount = BigInt.fromI32(0) 63 | pool.factoryID = event.address.toHexString() 64 | pool.tokensList = [] 65 | pool.tx = event.transaction.hash 66 | pool.save() 67 | 68 | factory.poolCount = factory.poolCount + 1 69 | factory.save() 70 | 71 | PoolContract.create(event.params.pool) 72 | } 73 | -------------------------------------------------------------------------------- /src/mappings/helpers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BigDecimal, 3 | Address, 4 | BigInt, 5 | Bytes, 6 | dataSource, 7 | ethereum 8 | } from '@graphprotocol/graph-ts' 9 | import { 10 | Pool, 11 | User, 12 | PoolToken, 13 | PoolShare, 14 | TokenPrice, 15 | Transaction, 16 | Balancer 17 | } from '../types/schema' 18 | import { BTokenBytes } from '../types/templates/Pool/BTokenBytes' 19 | import { BToken } from '../types/templates/Pool/BToken' 20 | import { CRPFactory } from '../types/Factory/CRPFactory' 21 | import { ConfigurableRightsPool } from '../types/Factory/ConfigurableRightsPool' 22 | 23 | export let ZERO_BD = BigDecimal.fromString('0') 24 | 25 | let network = dataSource.network() 26 | 27 | // Config for mainnet 28 | let WETH = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' 29 | let USD = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' 30 | let DAI = '0x6b175474e89094c44da98b954eedeac495271d0f' 31 | let CRP_FACTORY = '0xed52D8E202401645eDAD1c0AA21e872498ce47D0' 32 | 33 | if (network == 'kovan') { 34 | WETH = '0xd0a1e359811322d97991e03f863a0c30c2cf029c' 35 | USD = '0x2f375e94fc336cdec2dc0ccb5277fe59cbf1cae5' 36 | DAI = '0x1528f3fcc26d13f7079325fb78d9442607781c8c' 37 | CRP_FACTORY = '0x53265f0e014995363AE54DAd7059c018BaDbcD74' 38 | } 39 | 40 | if (network == 'rinkeby') { 41 | WETH = '0xc778417e063141139fce010982780140aa0cd5ab' 42 | USD = '0x21f3179cadae46509f615428f639e38123a508ac' 43 | DAI = '0x947b4082324af403047154f9f26f14538d775194' 44 | CRP_FACTORY = '0xA3F9145CB0B50D907930840BB2dcfF4146df8Ab4' 45 | } 46 | 47 | export function hexToDecimal(hexString: string, decimals: i32): BigDecimal { 48 | let bytes = Bytes.fromHexString(hexString).reverse() as Bytes 49 | let bi = BigInt.fromUnsignedBytes(bytes) 50 | let scale = BigInt.fromI32(10).pow(decimals as u8).toBigDecimal() 51 | return bi.divDecimal(scale) 52 | } 53 | 54 | export function bigIntToDecimal(amount: BigInt, decimals: i32): BigDecimal { 55 | let scale = BigInt.fromI32(10).pow(decimals as u8).toBigDecimal() 56 | return amount.toBigDecimal().div(scale) 57 | } 58 | 59 | export function tokenToDecimal(amount: BigDecimal, decimals: i32): BigDecimal { 60 | let scale = BigInt.fromI32(10).pow(decimals as u8).toBigDecimal() 61 | return amount.div(scale) 62 | } 63 | 64 | export function createPoolShareEntity(id: string, pool: string, user: string): void { 65 | let poolShare = new PoolShare(id) 66 | 67 | createUserEntity(user) 68 | 69 | poolShare.userAddress = user 70 | poolShare.poolId = pool 71 | poolShare.balance = ZERO_BD 72 | poolShare.save() 73 | } 74 | 75 | export function createPoolTokenEntity(id: string, pool: string, address: string): void { 76 | let token = BToken.bind(Address.fromString(address)) 77 | let tokenBytes = BTokenBytes.bind(Address.fromString(address)) 78 | let symbol = '' 79 | let name = '' 80 | let decimals = 18 81 | 82 | // COMMENT THE LINES BELOW OUT FOR LOCAL DEV ON KOVAN 83 | 84 | let symbolCall = token.try_symbol() 85 | let nameCall = token.try_name() 86 | let decimalCall = token.try_decimals() 87 | 88 | if (symbolCall.reverted) { 89 | let symbolBytesCall = tokenBytes.try_symbol() 90 | if (!symbolBytesCall.reverted) { 91 | symbol = symbolBytesCall.value.toString() 92 | } 93 | } else { 94 | symbol = symbolCall.value 95 | } 96 | 97 | if (nameCall.reverted) { 98 | let nameBytesCall = tokenBytes.try_name() 99 | if (!nameBytesCall.reverted) { 100 | name = nameBytesCall.value.toString() 101 | } 102 | } else { 103 | name = nameCall.value 104 | } 105 | 106 | if (!decimalCall.reverted) { 107 | decimals = decimalCall.value 108 | } 109 | 110 | // COMMENT THE LINES ABOVE OUT FOR LOCAL DEV ON KOVAN 111 | 112 | // !!! COMMENT THE LINES BELOW OUT FOR NON-LOCAL DEPLOYMENT 113 | // This code allows Symbols to be added when testing on local Kovan 114 | /* 115 | if(address == '0xd0a1e359811322d97991e03f863a0c30c2cf029c') 116 | symbol = 'WETH'; 117 | else if(address == '0x1528f3fcc26d13f7079325fb78d9442607781c8c') 118 | symbol = 'DAI' 119 | else if(address == '0xef13c0c8abcaf5767160018d268f9697ae4f5375') 120 | symbol = 'MKR' 121 | else if(address == '0x2f375e94fc336cdec2dc0ccb5277fe59cbf1cae5') 122 | symbol = 'USDC' 123 | else if(address == '0x1f1f156e0317167c11aa412e3d1435ea29dc3cce') 124 | symbol = 'BAT' 125 | else if(address == '0x86436bce20258a6dcfe48c9512d4d49a30c4d8c4') 126 | symbol = 'SNX' 127 | else if(address == '0x8c9e6c40d3402480ace624730524facc5482798c') 128 | symbol = 'REP' 129 | */ 130 | // !!! COMMENT THE LINES ABOVE OUT FOR NON-LOCAL DEPLOYMENT 131 | 132 | let poolToken = new PoolToken(id) 133 | poolToken.poolId = pool 134 | poolToken.address = address 135 | poolToken.name = name 136 | poolToken.symbol = symbol 137 | poolToken.decimals = decimals 138 | poolToken.balance = ZERO_BD 139 | poolToken.denormWeight = ZERO_BD 140 | poolToken.save() 141 | } 142 | 143 | export function updatePoolLiquidity(id: string): void { 144 | let pool = Pool.load(id) 145 | let tokensList: Array = pool.tokensList 146 | 147 | if (pool.tokensCount.equals(BigInt.fromI32(0))) { 148 | pool.liquidity = ZERO_BD 149 | pool.save() 150 | return 151 | } 152 | 153 | if (!tokensList || pool.tokensCount.lt(BigInt.fromI32(2)) || !pool.publicSwap) return 154 | 155 | // Find pool liquidity 156 | 157 | let hasPrice = false 158 | let hasUsdPrice = false 159 | let poolLiquidity = ZERO_BD 160 | 161 | if (tokensList.includes(Address.fromString(USD))) { 162 | let usdPoolTokenId = id.concat('-').concat(USD) 163 | let usdPoolToken = PoolToken.load(usdPoolTokenId) 164 | poolLiquidity = usdPoolToken.balance.div(usdPoolToken.denormWeight).times(pool.totalWeight) 165 | hasPrice = true 166 | hasUsdPrice = true 167 | } else if (tokensList.includes(Address.fromString(WETH))) { 168 | let wethTokenPrice = TokenPrice.load(WETH) 169 | if (wethTokenPrice !== null) { 170 | let poolTokenId = id.concat('-').concat(WETH) 171 | let poolToken = PoolToken.load(poolTokenId) 172 | poolLiquidity = wethTokenPrice.price.times(poolToken.balance).div(poolToken.denormWeight).times(pool.totalWeight) 173 | hasPrice = true 174 | } 175 | } else if (tokensList.includes(Address.fromString(DAI))) { 176 | let daiTokenPrice = TokenPrice.load(DAI) 177 | if (daiTokenPrice !== null) { 178 | let poolTokenId = id.concat('-').concat(DAI) 179 | let poolToken = PoolToken.load(poolTokenId) 180 | poolLiquidity = daiTokenPrice.price.times(poolToken.balance).div(poolToken.denormWeight).times(pool.totalWeight) 181 | hasPrice = true 182 | } 183 | } 184 | 185 | // Create or update token price 186 | 187 | if (hasPrice) { 188 | for (let i: i32 = 0; i < tokensList.length; i++) { 189 | let tokenPriceId = tokensList[i].toHexString() 190 | let tokenPrice = TokenPrice.load(tokenPriceId) 191 | if (tokenPrice == null) { 192 | tokenPrice = new TokenPrice(tokenPriceId) 193 | tokenPrice.poolTokenId = '' 194 | tokenPrice.poolLiquidity = ZERO_BD 195 | } 196 | 197 | let poolTokenId = id.concat('-').concat(tokenPriceId) 198 | let poolToken = PoolToken.load(poolTokenId) 199 | 200 | if ( 201 | pool.active && !pool.crp && pool.tokensCount.notEqual(BigInt.fromI32(0)) && pool.publicSwap && 202 | (tokenPrice.poolTokenId == poolTokenId || poolLiquidity.gt(tokenPrice.poolLiquidity)) && 203 | ( 204 | (tokenPriceId != WETH.toString() && tokenPriceId != DAI.toString()) || 205 | (pool.tokensCount.equals(BigInt.fromI32(2)) && hasUsdPrice) 206 | ) 207 | ) { 208 | tokenPrice.price = ZERO_BD 209 | 210 | if (poolToken.balance.gt(ZERO_BD)) { 211 | tokenPrice.price = poolLiquidity.div(pool.totalWeight).times(poolToken.denormWeight).div(poolToken.balance) 212 | } 213 | 214 | tokenPrice.symbol = poolToken.symbol 215 | tokenPrice.name = poolToken.name 216 | tokenPrice.decimals = poolToken.decimals 217 | tokenPrice.poolLiquidity = poolLiquidity 218 | tokenPrice.poolTokenId = poolTokenId 219 | tokenPrice.save() 220 | } 221 | } 222 | } 223 | 224 | // Update pool liquidity 225 | 226 | let liquidity = ZERO_BD 227 | let denormWeight = ZERO_BD 228 | 229 | for (let i: i32 = 0; i < tokensList.length; i++) { 230 | let tokenPriceId = tokensList[i].toHexString() 231 | let tokenPrice = TokenPrice.load(tokenPriceId) 232 | if (tokenPrice !== null) { 233 | let poolTokenId = id.concat('-').concat(tokenPriceId) 234 | let poolToken = PoolToken.load(poolTokenId) 235 | if (tokenPrice.price.gt(ZERO_BD) && poolToken.denormWeight.gt(denormWeight)) { 236 | denormWeight = poolToken.denormWeight 237 | liquidity = tokenPrice.price.times(poolToken.balance).div(poolToken.denormWeight).times(pool.totalWeight) 238 | } 239 | } 240 | } 241 | 242 | let factory = Balancer.load('1') 243 | factory.totalLiquidity = factory.totalLiquidity.minus(pool.liquidity).plus(liquidity) 244 | factory.save() 245 | 246 | pool.liquidity = liquidity 247 | pool.save() 248 | } 249 | 250 | export function decrPoolCount(active: boolean, finalized: boolean, crp: boolean): void { 251 | if (active) { 252 | let factory = Balancer.load('1') 253 | factory.poolCount = factory.poolCount - 1 254 | if (finalized) factory.finalizedPoolCount = factory.finalizedPoolCount - 1 255 | if (crp) factory.crpCount = factory.crpCount - 1 256 | factory.save() 257 | } 258 | } 259 | 260 | export function saveTransaction(event: ethereum.Event, eventName: string): void { 261 | let tx = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()) 262 | let userAddress = event.transaction.from.toHex() 263 | let transaction = Transaction.load(tx) 264 | if (transaction == null) { 265 | transaction = new Transaction(tx) 266 | } 267 | transaction.event = eventName 268 | transaction.poolAddress = event.address.toHex() 269 | transaction.userAddress = userAddress 270 | transaction.gasUsed = event.transaction.gasUsed.toBigDecimal() 271 | transaction.gasPrice = event.transaction.gasPrice.toBigDecimal() 272 | transaction.tx = event.transaction.hash 273 | transaction.timestamp = event.block.timestamp.toI32() 274 | transaction.block = event.block.number.toI32() 275 | transaction.save() 276 | 277 | createUserEntity(userAddress) 278 | } 279 | 280 | export function createUserEntity(address: string): void { 281 | if (User.load(address) == null) { 282 | let user = new User(address) 283 | user.save() 284 | } 285 | } 286 | 287 | export function isCrp(address: Address): boolean { 288 | let crpFactory = CRPFactory.bind(Address.fromString(CRP_FACTORY)) 289 | let isCrp = crpFactory.try_isCrp(address) 290 | if (isCrp.reverted) return false 291 | return isCrp.value 292 | } 293 | 294 | export function getCrpUnderlyingPool(crp: ConfigurableRightsPool): string | null { 295 | let bPool = crp.try_bPool() 296 | if (bPool.reverted) return null; 297 | return bPool.value.toHexString() 298 | } 299 | 300 | export function getCrpController(crp: ConfigurableRightsPool): string | null { 301 | let controller = crp.try_getController() 302 | if (controller.reverted) return null; 303 | return controller.value.toHexString() 304 | } 305 | 306 | export function getCrpSymbol(crp: ConfigurableRightsPool): string { 307 | let symbol = crp.try_symbol() 308 | if (symbol.reverted) return '' 309 | return symbol.value 310 | } 311 | 312 | export function getCrpName(crp: ConfigurableRightsPool): string { 313 | let name = crp.try_name() 314 | if (name.reverted) return '' 315 | return name.value 316 | } 317 | 318 | export function getCrpCap(crp: ConfigurableRightsPool): BigInt { 319 | let cap = crp.try_getCap() 320 | if (cap.reverted) return BigInt.fromI32(0) 321 | return cap.value 322 | } 323 | 324 | export function getCrpRights(crp: ConfigurableRightsPool): string[] { 325 | let rights = crp.try_rights() 326 | if (rights.reverted) return [] 327 | let rightsArr: string[] = [] 328 | if (rights.value.value0) rightsArr.push('canPauseSwapping') 329 | if (rights.value.value1) rightsArr.push('canChangeSwapFee') 330 | if (rights.value.value2) rightsArr.push('canChangeWeights') 331 | if (rights.value.value3) rightsArr.push('canAddRemoveTokens') 332 | if (rights.value.value4) rightsArr.push('canWhitelistLPs') 333 | if (rights.value.value5) rightsArr.push('canChangeCap') 334 | return rightsArr 335 | } 336 | -------------------------------------------------------------------------------- /src/mappings/pool.ts: -------------------------------------------------------------------------------- 1 | import { BigInt, Address, Bytes, store } from '@graphprotocol/graph-ts' 2 | import { LOG_CALL, LOG_JOIN, LOG_EXIT, LOG_SWAP, Transfer, GulpCall } from '../types/templates/Pool/Pool' 3 | import { Pool as BPool } from '../types/templates/Pool/Pool' 4 | import { 5 | Balancer, 6 | Pool, 7 | PoolToken, 8 | PoolShare, 9 | Swap, 10 | TokenPrice 11 | } from '../types/schema' 12 | import { 13 | hexToDecimal, 14 | bigIntToDecimal, 15 | tokenToDecimal, 16 | createPoolShareEntity, 17 | createPoolTokenEntity, 18 | updatePoolLiquidity, 19 | getCrpUnderlyingPool, 20 | saveTransaction, 21 | ZERO_BD, 22 | decrPoolCount 23 | } from './helpers' 24 | import { ConfigurableRightsPool, OwnershipTransferred } from '../types/Factory/ConfigurableRightsPool' 25 | 26 | /************************************ 27 | ********** Pool Controls *********** 28 | ************************************/ 29 | 30 | export function handleSetSwapFee(event: LOG_CALL): void { 31 | let poolId = event.address.toHex() 32 | let pool = Pool.load(poolId) 33 | let swapFee = hexToDecimal(event.params.data.toHexString().slice(-40), 18) 34 | pool.swapFee = swapFee 35 | pool.save() 36 | 37 | saveTransaction(event, 'setSwapFee') 38 | } 39 | 40 | export function handleSetController(event: LOG_CALL): void { 41 | let poolId = event.address.toHex() 42 | let pool = Pool.load(poolId) 43 | let controller = Address.fromString(event.params.data.toHexString().slice(-40)) 44 | pool.controller = controller 45 | pool.save() 46 | 47 | saveTransaction(event, 'setController') 48 | } 49 | 50 | export function handleSetCrpController(event: OwnershipTransferred): void { 51 | // This event occurs on the CRP contract rather than the underlying pool so we must perform a lookup. 52 | let crp = ConfigurableRightsPool.bind(event.address) 53 | let pool = Pool.load(getCrpUnderlyingPool(crp)) 54 | pool.crpController = event.params.newOwner 55 | pool.save() 56 | 57 | // We overwrite event address so that ownership transfers can be linked to Pool entities for above reason. 58 | event.address = Address.fromString(pool.id) 59 | saveTransaction(event, 'setCrpController') 60 | } 61 | 62 | 63 | export function handleSetPublicSwap(event: LOG_CALL): void { 64 | let poolId = event.address.toHex() 65 | let pool = Pool.load(poolId) 66 | let publicSwap = event.params.data.toHexString().slice(-1) == '1' 67 | pool.publicSwap = publicSwap 68 | pool.save() 69 | 70 | saveTransaction(event, 'setPublicSwap') 71 | } 72 | 73 | export function handleFinalize(event: LOG_CALL): void { 74 | let poolId = event.address.toHex() 75 | let pool = Pool.load(poolId) 76 | // let balance = BigDecimal.fromString('100') 77 | pool.finalized = true 78 | pool.symbol = 'BPT' 79 | pool.publicSwap = true 80 | // pool.totalShares = balance 81 | pool.save() 82 | 83 | /* 84 | let poolShareId = poolId.concat('-').concat(event.params.caller.toHex()) 85 | let poolShare = PoolShare.load(poolShareId) 86 | if (poolShare == null) { 87 | createPoolShareEntity(poolShareId, poolId, event.params.caller.toHex()) 88 | poolShare = PoolShare.load(poolShareId) 89 | } 90 | poolShare.balance = balance 91 | poolShare.save() 92 | */ 93 | 94 | let factory = Balancer.load('1') 95 | factory.finalizedPoolCount = factory.finalizedPoolCount + 1 96 | factory.save() 97 | 98 | saveTransaction(event, 'finalize') 99 | } 100 | 101 | export function handleRebind(event: LOG_CALL): void { 102 | let poolId = event.address.toHex() 103 | let pool = Pool.load(poolId) 104 | let tokenBytes = Bytes.fromHexString(event.params.data.toHexString().slice(34,74)) as Bytes 105 | let tokensList = pool.tokensList || [] 106 | if (tokensList.indexOf(tokenBytes) == -1 ) { 107 | tokensList.push(tokenBytes) 108 | } 109 | pool.tokensList = tokensList 110 | pool.tokensCount = BigInt.fromI32(tokensList.length) 111 | 112 | let address = Address.fromString(event.params.data.toHexString().slice(34,74)) 113 | let denormWeight = hexToDecimal(event.params.data.toHexString().slice(138), 18) 114 | 115 | let poolTokenId = poolId.concat('-').concat(address.toHexString()) 116 | let poolToken = PoolToken.load(poolTokenId) 117 | if (poolToken == null) { 118 | createPoolTokenEntity(poolTokenId, poolId, address.toHexString()) 119 | poolToken = PoolToken.load(poolTokenId) 120 | pool.totalWeight += denormWeight 121 | } else { 122 | let oldWeight = poolToken.denormWeight 123 | if (denormWeight > oldWeight) { 124 | pool.totalWeight = pool.totalWeight + (denormWeight - oldWeight) 125 | } else { 126 | pool.totalWeight = pool.totalWeight - (oldWeight - denormWeight) 127 | } 128 | } 129 | 130 | let balance = hexToDecimal(event.params.data.toHexString().slice(74,138), poolToken.decimals) 131 | 132 | poolToken.balance = balance 133 | poolToken.denormWeight = denormWeight 134 | poolToken.save() 135 | 136 | if (balance.equals(ZERO_BD)) { 137 | decrPoolCount(pool.active, pool.finalized, pool.crp) 138 | pool.active = false 139 | } 140 | pool.save() 141 | 142 | updatePoolLiquidity(poolId) 143 | saveTransaction(event, 'rebind') 144 | } 145 | 146 | export function handleUnbind(event: LOG_CALL): void { 147 | let poolId = event.address.toHex() 148 | let pool = Pool.load(poolId) 149 | let tokenBytes = Bytes.fromHexString(event.params.data.toHexString().slice(-40)) as Bytes 150 | let tokensList = pool.tokensList || [] 151 | let index = tokensList.indexOf(tokenBytes) 152 | tokensList.splice(index, 1) 153 | pool.tokensList = tokensList 154 | pool.tokensCount = BigInt.fromI32(tokensList.length) 155 | 156 | 157 | let address = Address.fromString(event.params.data.toHexString().slice(-40)) 158 | let poolTokenId = poolId.concat('-').concat(address.toHexString()) 159 | let poolToken = PoolToken.load(poolTokenId) 160 | pool.totalWeight -= poolToken.denormWeight 161 | pool.save() 162 | store.remove('PoolToken', poolTokenId) 163 | 164 | updatePoolLiquidity(poolId) 165 | saveTransaction(event, 'unbind') 166 | } 167 | 168 | export function handleGulp(call: GulpCall): void { 169 | let poolId = call.to.toHexString() 170 | let pool = Pool.load(poolId) 171 | 172 | let address = call.inputs.token.toHexString() 173 | 174 | let bpool = BPool.bind(Address.fromString(poolId)) 175 | let balanceCall = bpool.try_getBalance(Address.fromString(address)) 176 | 177 | let poolTokenId = poolId.concat('-').concat(address) 178 | let poolToken = PoolToken.load(poolTokenId) 179 | 180 | if (poolToken != null) { 181 | let balance = ZERO_BD 182 | if (!balanceCall.reverted) { 183 | balance = bigIntToDecimal(balanceCall.value, poolToken.decimals) 184 | } 185 | poolToken.balance = balance 186 | poolToken.save() 187 | } 188 | 189 | updatePoolLiquidity(poolId) 190 | } 191 | 192 | /************************************ 193 | ********** JOINS & EXITS *********** 194 | ************************************/ 195 | 196 | export function handleJoinPool(event: LOG_JOIN): void { 197 | let poolId = event.address.toHex() 198 | let pool = Pool.load(poolId) 199 | pool.joinsCount += BigInt.fromI32(1) 200 | pool.save() 201 | 202 | let address = event.params.tokenIn.toHex() 203 | let poolTokenId = poolId.concat('-').concat(address.toString()) 204 | let poolToken = PoolToken.load(poolTokenId) 205 | let tokenAmountIn = tokenToDecimal(event.params.tokenAmountIn.toBigDecimal(), poolToken.decimals) 206 | let newAmount = poolToken.balance.plus(tokenAmountIn) 207 | poolToken.balance = newAmount 208 | poolToken.save() 209 | 210 | updatePoolLiquidity(poolId) 211 | saveTransaction(event, 'join') 212 | } 213 | 214 | export function handleExitPool(event: LOG_EXIT): void { 215 | let poolId = event.address.toHex() 216 | 217 | let address = event.params.tokenOut.toHex() 218 | let poolTokenId = poolId.concat('-').concat(address.toString()) 219 | let poolToken = PoolToken.load(poolTokenId) 220 | let tokenAmountOut = tokenToDecimal(event.params.tokenAmountOut.toBigDecimal(), poolToken.decimals) 221 | let newAmount = poolToken.balance.minus(tokenAmountOut) 222 | poolToken.balance = newAmount 223 | poolToken.save() 224 | 225 | let pool = Pool.load(poolId) 226 | pool.exitsCount += BigInt.fromI32(1) 227 | if (newAmount.equals(ZERO_BD)) { 228 | decrPoolCount(pool.active, pool.finalized, pool.crp) 229 | pool.active = false 230 | } 231 | pool.save() 232 | 233 | updatePoolLiquidity(poolId) 234 | saveTransaction(event, 'exit') 235 | } 236 | 237 | /************************************ 238 | ************** SWAPS *************** 239 | ************************************/ 240 | 241 | export function handleSwap(event: LOG_SWAP): void { 242 | let poolId = event.address.toHex() 243 | 244 | let tokenIn = event.params.tokenIn.toHex() 245 | let poolTokenInId = poolId.concat('-').concat(tokenIn.toString()) 246 | let poolTokenIn = PoolToken.load(poolTokenInId) 247 | let tokenAmountIn = tokenToDecimal(event.params.tokenAmountIn.toBigDecimal(), poolTokenIn.decimals) 248 | let newAmountIn = poolTokenIn.balance.plus(tokenAmountIn) 249 | poolTokenIn.balance = newAmountIn 250 | poolTokenIn.save() 251 | 252 | let tokenOut = event.params.tokenOut.toHex() 253 | let poolTokenOutId = poolId.concat('-').concat(tokenOut.toString()) 254 | let poolTokenOut = PoolToken.load(poolTokenOutId) 255 | let tokenAmountOut = tokenToDecimal(event.params.tokenAmountOut.toBigDecimal(), poolTokenOut.decimals) 256 | let newAmountOut = poolTokenOut.balance.minus(tokenAmountOut) 257 | poolTokenOut.balance = newAmountOut 258 | poolTokenOut.save() 259 | 260 | updatePoolLiquidity(poolId) 261 | 262 | let swapId = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()) 263 | let swap = Swap.load(swapId) 264 | if (swap == null) { 265 | swap = new Swap(swapId) 266 | } 267 | 268 | let pool = Pool.load(poolId) 269 | let tokensList: Array = pool.tokensList 270 | let tokenOutPriceValue = ZERO_BD 271 | let tokenOutPrice = TokenPrice.load(tokenOut) 272 | 273 | if (tokenOutPrice != null) { 274 | tokenOutPriceValue = tokenOutPrice.price 275 | } else { 276 | for (let i: i32 = 0; i < tokensList.length; i++) { 277 | let tokenPriceId = tokensList[i].toHexString() 278 | if (!tokenOutPriceValue.gt(ZERO_BD) && tokenPriceId !== tokenOut) { 279 | let tokenPrice = TokenPrice.load(tokenPriceId) 280 | if (tokenPrice !== null && tokenPrice.price.gt(ZERO_BD)) { 281 | let poolTokenId = poolId.concat('-').concat(tokenPriceId) 282 | let poolToken = PoolToken.load(poolTokenId) 283 | tokenOutPriceValue = tokenPrice.price 284 | .times(poolToken.balance) 285 | .div(poolToken.denormWeight) 286 | .times(poolTokenOut.denormWeight) 287 | .div(poolTokenOut.balance) 288 | } 289 | } 290 | } 291 | } 292 | 293 | let totalSwapVolume = pool.totalSwapVolume 294 | let totalSwapFee = pool.totalSwapFee 295 | let liquidity = pool.liquidity 296 | let swapValue = ZERO_BD 297 | let swapFeeValue = ZERO_BD 298 | let factory = Balancer.load('1') 299 | 300 | if (tokenOutPriceValue.gt(ZERO_BD)) { 301 | swapValue = tokenOutPriceValue.times(tokenAmountOut) 302 | swapFeeValue = swapValue.times(pool.swapFee) 303 | totalSwapVolume = totalSwapVolume.plus(swapValue) 304 | totalSwapFee = totalSwapFee.plus(swapFeeValue) 305 | 306 | 307 | factory.totalSwapVolume = factory.totalSwapVolume.plus(swapValue) 308 | factory.totalSwapFee = factory.totalSwapFee.plus(swapFeeValue) 309 | 310 | pool.totalSwapVolume = totalSwapVolume 311 | pool.totalSwapFee = totalSwapFee 312 | } 313 | 314 | pool.swapsCount += BigInt.fromI32(1) 315 | factory.txCount += BigInt.fromI32(1) 316 | factory.save() 317 | 318 | if (newAmountIn.equals(ZERO_BD) || newAmountOut.equals(ZERO_BD)) { 319 | decrPoolCount(pool.active, pool.finalized, pool.crp) 320 | pool.active = false 321 | } 322 | pool.save() 323 | 324 | swap.caller = event.params.caller 325 | swap.tokenIn = event.params.tokenIn 326 | swap.tokenInSym = poolTokenIn.symbol 327 | swap.tokenOut = event.params.tokenOut 328 | swap.tokenOutSym = poolTokenOut.symbol 329 | swap.tokenAmountIn = tokenAmountIn 330 | swap.tokenAmountOut = tokenAmountOut 331 | swap.poolAddress = event.address.toHex() 332 | swap.userAddress = event.transaction.from.toHex() 333 | swap.poolTotalSwapVolume = totalSwapVolume 334 | swap.poolTotalSwapFee = totalSwapFee 335 | swap.poolLiquidity = liquidity 336 | swap.value = swapValue 337 | swap.feeValue = swapFeeValue 338 | swap.timestamp = event.block.timestamp.toI32() 339 | swap.save() 340 | 341 | saveTransaction(event, 'swap') 342 | } 343 | 344 | /************************************ 345 | *********** POOL SHARES ************ 346 | ************************************/ 347 | 348 | export function handleTransfer(event: Transfer): void { 349 | let poolId = event.address.toHex() 350 | 351 | let ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' 352 | 353 | let isMint = event.params.src.toHex() == ZERO_ADDRESS 354 | let isBurn = event.params.dst.toHex() == ZERO_ADDRESS 355 | 356 | let poolShareFromId = poolId.concat('-').concat(event.params.src.toHex()) 357 | let poolShareFrom = PoolShare.load(poolShareFromId) 358 | let poolShareFromBalance = poolShareFrom == null ? ZERO_BD : poolShareFrom.balance 359 | 360 | let poolShareToId = poolId.concat('-').concat(event.params.dst.toHex()) 361 | let poolShareTo = PoolShare.load(poolShareToId) 362 | let poolShareToBalance = poolShareTo == null ? ZERO_BD : poolShareTo.balance 363 | 364 | let pool = Pool.load(poolId) 365 | 366 | if (isMint) { 367 | if (poolShareTo == null) { 368 | createPoolShareEntity(poolShareToId, poolId, event.params.dst.toHex()) 369 | poolShareTo = PoolShare.load(poolShareToId) 370 | } 371 | poolShareTo.balance += tokenToDecimal(event.params.amt.toBigDecimal(), 18) 372 | poolShareTo.save() 373 | pool.totalShares += tokenToDecimal(event.params.amt.toBigDecimal(), 18) 374 | } else if (isBurn) { 375 | if (poolShareFrom == null) { 376 | createPoolShareEntity(poolShareFromId, poolId, event.params.src.toHex()) 377 | poolShareFrom = PoolShare.load(poolShareFromId) 378 | } 379 | poolShareFrom.balance -= tokenToDecimal(event.params.amt.toBigDecimal(), 18) 380 | poolShareFrom.save() 381 | pool.totalShares -= tokenToDecimal(event.params.amt.toBigDecimal(), 18) 382 | } else { 383 | if (poolShareTo == null) { 384 | createPoolShareEntity(poolShareToId, poolId, event.params.dst.toHex()) 385 | poolShareTo = PoolShare.load(poolShareToId) 386 | } 387 | poolShareTo.balance += tokenToDecimal(event.params.amt.toBigDecimal(), 18) 388 | poolShareTo.save() 389 | 390 | if (poolShareFrom == null) { 391 | createPoolShareEntity(poolShareFromId, poolId, event.params.src.toHex()) 392 | poolShareFrom = PoolShare.load(poolShareFromId) 393 | } 394 | poolShareFrom.balance -= tokenToDecimal(event.params.amt.toBigDecimal(), 18) 395 | poolShareFrom.save() 396 | } 397 | 398 | if ( 399 | poolShareTo !== null 400 | && poolShareTo.balance.notEqual(ZERO_BD) 401 | && poolShareToBalance.equals(ZERO_BD) 402 | ) { 403 | pool.holdersCount += BigInt.fromI32(1) 404 | } 405 | 406 | if ( 407 | poolShareFrom !== null 408 | && poolShareFrom.balance.equals(ZERO_BD) 409 | && poolShareFromBalance.notEqual(ZERO_BD) 410 | ) { 411 | pool.holdersCount -= BigInt.fromI32(1) 412 | } 413 | 414 | pool.save() 415 | } 416 | -------------------------------------------------------------------------------- /subgraph.kovan.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | description: Balancer is a non-custodial portfolio manager, liquidity provider, and price sensor. 3 | repository: https://github.com/balancer-labs/balancer-subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: Factory 9 | network: kovan 10 | source: 11 | address: "0x8f7F78080219d4066A8036ccD30D588B416a40DB" 12 | abi: Factory 13 | startBlock: 16337546 14 | mapping: 15 | kind: ethereum/events 16 | apiVersion: 0.0.4 17 | language: wasm/assemblyscript 18 | file: ./src/mappings/factory.ts 19 | entities: 20 | - Balancer 21 | abis: 22 | - name: Factory 23 | file: ./abis/BFactory.json 24 | - name: CRPFactory 25 | file: ./abis/CRPFactory.json 26 | - name: ConfigurableRightsPool 27 | file: ./abis/ConfigurableRightsPool.json 28 | eventHandlers: 29 | - event: LOG_NEW_POOL(indexed address,indexed address) 30 | handler: handleNewPool 31 | templates: 32 | - kind: ethereum/contract 33 | name: Pool 34 | network: kovan 35 | source: 36 | abi: Pool 37 | mapping: 38 | kind: ethereum/events 39 | apiVersion: 0.0.4 40 | language: wasm/assemblyscript 41 | file: ./src/mappings/pool.ts 42 | entities: 43 | - Pool 44 | - Balancer 45 | - Swap 46 | abis: 47 | - name: Pool 48 | file: ./abis/BPool.json 49 | - name: BToken 50 | file: ./abis/BToken.json 51 | - name: BTokenBytes 52 | file: ./abis/BTokenBytes32.json 53 | eventHandlers: 54 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 55 | topic0: "0x34e1990700000000000000000000000000000000000000000000000000000000" 56 | handler: handleSetSwapFee 57 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 58 | topic0: "0x92eefe9b00000000000000000000000000000000000000000000000000000000" 59 | handler: handleSetController 60 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 61 | topic0: "0x49b5955200000000000000000000000000000000000000000000000000000000" 62 | handler: handleSetPublicSwap 63 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 64 | topic0: "0x4bb278f300000000000000000000000000000000000000000000000000000000" 65 | handler: handleFinalize 66 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 67 | topic0: "0x3fdddaa200000000000000000000000000000000000000000000000000000000" 68 | handler: handleRebind 69 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 70 | topic0: "0xe4e1e53800000000000000000000000000000000000000000000000000000000" 71 | handler: handleRebind 72 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 73 | topic0: "0xcf5e7bd300000000000000000000000000000000000000000000000000000000" 74 | handler: handleUnbind 75 | - event: LOG_JOIN(indexed address,indexed address,uint256) 76 | handler: handleJoinPool 77 | - event: LOG_EXIT(indexed address,indexed address,uint256) 78 | handler: handleExitPool 79 | - event: LOG_SWAP(indexed address,indexed address,indexed address,uint256,uint256) 80 | handler: handleSwap 81 | - event: Transfer(indexed address,indexed address,uint256) 82 | handler: handleTransfer 83 | callHandlers: 84 | - function: gulp(address) 85 | handler: handleGulp 86 | - kind: ethereum/contract 87 | name: CrpController 88 | network: kovan 89 | source: 90 | abi: ConfigurableRightsPool 91 | mapping: 92 | kind: ethereum/events 93 | apiVersion: 0.0.4 94 | language: wasm/assemblyscript 95 | file: ./src/mappings/pool.ts 96 | entities: 97 | - Pool 98 | abis: 99 | - name: ConfigurableRightsPool 100 | file: ./abis/ConfigurableRightsPool.json 101 | eventHandlers: 102 | - event: OwnershipTransferred(indexed address,indexed address) 103 | handler: handleSetCrpController -------------------------------------------------------------------------------- /subgraph.rinkeby.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | description: Balancer is a non-custodial portfolio manager, liquidity provider, and price sensor. 3 | repository: https://github.com/balancer-labs/balancer-subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: Factory 9 | network: rinkeby 10 | source: 11 | address: "0x9C84391B443ea3a48788079a5f98e2EaD55c9309" 12 | abi: Factory 13 | startBlock: 6881181 14 | mapping: 15 | kind: ethereum/events 16 | apiVersion: 0.0.4 17 | language: wasm/assemblyscript 18 | file: ./src/mappings/factory.ts 19 | entities: 20 | - Balancer 21 | abis: 22 | - name: Factory 23 | file: ./abis/BFactory.json 24 | - name: CRPFactory 25 | file: ./abis/CRPFactory.json 26 | - name: ConfigurableRightsPool 27 | file: ./abis/ConfigurableRightsPool.json 28 | eventHandlers: 29 | - event: LOG_NEW_POOL(indexed address,indexed address) 30 | handler: handleNewPool 31 | templates: 32 | - kind: ethereum/contract 33 | name: Pool 34 | network: rinkeby 35 | source: 36 | abi: Pool 37 | mapping: 38 | kind: ethereum/events 39 | apiVersion: 0.0.4 40 | language: wasm/assemblyscript 41 | file: ./src/mappings/pool.ts 42 | entities: 43 | - Pool 44 | - Balancer 45 | - Swap 46 | abis: 47 | - name: Pool 48 | file: ./abis/BPool.json 49 | - name: BToken 50 | file: ./abis/BToken.json 51 | - name: BTokenBytes 52 | file: ./abis/BTokenBytes32.json 53 | eventHandlers: 54 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 55 | topic0: "0x34e1990700000000000000000000000000000000000000000000000000000000" 56 | handler: handleSetSwapFee 57 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 58 | topic0: "0x92eefe9b00000000000000000000000000000000000000000000000000000000" 59 | handler: handleSetController 60 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 61 | topic0: "0x49b5955200000000000000000000000000000000000000000000000000000000" 62 | handler: handleSetPublicSwap 63 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 64 | topic0: "0x4bb278f300000000000000000000000000000000000000000000000000000000" 65 | handler: handleFinalize 66 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 67 | topic0: "0x3fdddaa200000000000000000000000000000000000000000000000000000000" 68 | handler: handleRebind 69 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 70 | topic0: "0xe4e1e53800000000000000000000000000000000000000000000000000000000" 71 | handler: handleRebind 72 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 73 | topic0: "0xcf5e7bd300000000000000000000000000000000000000000000000000000000" 74 | handler: handleUnbind 75 | - event: LOG_JOIN(indexed address,indexed address,uint256) 76 | handler: handleJoinPool 77 | - event: LOG_EXIT(indexed address,indexed address,uint256) 78 | handler: handleExitPool 79 | - event: LOG_SWAP(indexed address,indexed address,indexed address,uint256,uint256) 80 | handler: handleSwap 81 | - event: Transfer(indexed address,indexed address,uint256) 82 | handler: handleTransfer 83 | - kind: ethereum/contract 84 | name: CrpController 85 | network: rinkeby 86 | source: 87 | abi: ConfigurableRightsPool 88 | mapping: 89 | kind: ethereum/events 90 | apiVersion: 0.0.4 91 | language: wasm/assemblyscript 92 | file: ./src/mappings/pool.ts 93 | entities: 94 | - Pool 95 | abis: 96 | - name: ConfigurableRightsPool 97 | file: ./abis/ConfigurableRightsPool.json 98 | eventHandlers: 99 | - event: OwnershipTransferred(indexed address,indexed address) 100 | handler: handleSetCrpController -------------------------------------------------------------------------------- /subgraph.ropsten.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | description: Balancer is a non-custodial portfolio manager, liquidity provider, and price sensor. 3 | repository: https://github.com/balancer-labs/balancer-subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: Factory 9 | network: ropsten 10 | source: 11 | address: "0xeb12Ce3D5C1B34baa3e3dF03D61fCBf4A3E45104" 12 | abi: Factory 13 | startBlock: 7696706 14 | mapping: 15 | kind: ethereum/events 16 | apiVersion: 0.0.3 17 | language: wasm/assemblyscript 18 | file: ./src/mappings/factory.ts 19 | entities: 20 | - Balancer 21 | abis: 22 | - name: Factory 23 | file: ./abis/BFactory.json 24 | - name: CRPFactory 25 | file: ./abis/CRPFactory.json 26 | - name: ConfigurableRightsPool 27 | file: ./abis/ConfigurableRightsPool.json 28 | eventHandlers: 29 | - event: LOG_NEW_POOL(indexed address,indexed address) 30 | handler: handleNewPool 31 | templates: 32 | - kind: ethereum/contract 33 | name: Pool 34 | network: ropsten 35 | source: 36 | abi: Pool 37 | mapping: 38 | kind: ethereum/events 39 | apiVersion: 0.0.3 40 | language: wasm/assemblyscript 41 | file: ./src/mappings/pool.ts 42 | entities: 43 | - Pool 44 | - Balancer 45 | - Swap 46 | abis: 47 | - name: Pool 48 | file: ./abis/BPool.json 49 | - name: BToken 50 | file: ./abis/BToken.json 51 | - name: BTokenBytes 52 | file: ./abis/BTokenBytes32.json 53 | eventHandlers: 54 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 55 | topic0: "0x34e1990700000000000000000000000000000000000000000000000000000000" 56 | handler: handleSetSwapFee 57 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 58 | topic0: "0x92eefe9b00000000000000000000000000000000000000000000000000000000" 59 | handler: handleSetController 60 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 61 | topic0: "0x49b5955200000000000000000000000000000000000000000000000000000000" 62 | handler: handleSetPublicSwap 63 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 64 | topic0: "0x4bb278f300000000000000000000000000000000000000000000000000000000" 65 | handler: handleFinalize 66 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 67 | topic0: "0x3fdddaa200000000000000000000000000000000000000000000000000000000" 68 | handler: handleRebind 69 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 70 | topic0: "0xe4e1e53800000000000000000000000000000000000000000000000000000000" 71 | handler: handleRebind 72 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 73 | topic0: "0xcf5e7bd300000000000000000000000000000000000000000000000000000000" 74 | handler: handleUnbind 75 | - event: LOG_JOIN(indexed address,indexed address,uint256) 76 | handler: handleJoinPool 77 | - event: LOG_EXIT(indexed address,indexed address,uint256) 78 | handler: handleExitPool 79 | - event: LOG_SWAP(indexed address,indexed address,indexed address,uint256,uint256) 80 | handler: handleSwap 81 | - event: Transfer(indexed address,indexed address,uint256) 82 | handler: handleTransfer 83 | - kind: ethereum/contract 84 | name: CrpController 85 | network: ropsten 86 | source: 87 | abi: ConfigurableRightsPool 88 | mapping: 89 | kind: ethereum/events 90 | apiVersion: 0.0.4 91 | language: wasm/assemblyscript 92 | file: ./src/mappings/pool.ts 93 | entities: 94 | - Pool 95 | abis: 96 | - name: ConfigurableRightsPool 97 | file: ./abis/ConfigurableRightsPool.json 98 | eventHandlers: 99 | - event: OwnershipTransferred(indexed address,indexed address) 100 | handler: handleSetCrpController -------------------------------------------------------------------------------- /subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | description: Balancer is a non-custodial portfolio manager, liquidity provider, and price sensor. 3 | repository: https://github.com/balancer-labs/balancer-subgraph 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: Factory 9 | network: mainnet 10 | source: 11 | address: "0x9424B1412450D0f8Fc2255FAf6046b98213B76Bd" 12 | abi: Factory 13 | startBlock: 9562480 14 | mapping: 15 | kind: ethereum/events 16 | apiVersion: 0.0.4 17 | language: wasm/assemblyscript 18 | file: ./src/mappings/factory.ts 19 | entities: 20 | - Balancer 21 | abis: 22 | - name: Factory 23 | file: ./abis/BFactory.json 24 | - name: CRPFactory 25 | file: ./abis/CRPFactory.json 26 | - name: ConfigurableRightsPool 27 | file: ./abis/ConfigurableRightsPool.json 28 | eventHandlers: 29 | - event: LOG_NEW_POOL(indexed address,indexed address) 30 | handler: handleNewPool 31 | templates: 32 | - kind: ethereum/contract 33 | name: Pool 34 | network: mainnet 35 | source: 36 | abi: Pool 37 | mapping: 38 | kind: ethereum/events 39 | apiVersion: 0.0.4 40 | language: wasm/assemblyscript 41 | file: ./src/mappings/pool.ts 42 | entities: 43 | - Pool 44 | - Balancer 45 | - Swap 46 | abis: 47 | - name: Pool 48 | file: ./abis/BPool.json 49 | - name: BToken 50 | file: ./abis/BToken.json 51 | - name: BTokenBytes 52 | file: ./abis/BTokenBytes32.json 53 | eventHandlers: 54 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 55 | topic0: "0x34e1990700000000000000000000000000000000000000000000000000000000" 56 | handler: handleSetSwapFee 57 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 58 | topic0: "0x92eefe9b00000000000000000000000000000000000000000000000000000000" 59 | handler: handleSetController 60 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 61 | topic0: "0x49b5955200000000000000000000000000000000000000000000000000000000" 62 | handler: handleSetPublicSwap 63 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 64 | topic0: "0x4bb278f300000000000000000000000000000000000000000000000000000000" 65 | handler: handleFinalize 66 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 67 | topic0: "0x3fdddaa200000000000000000000000000000000000000000000000000000000" 68 | handler: handleRebind 69 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 70 | topic0: "0xe4e1e53800000000000000000000000000000000000000000000000000000000" 71 | handler: handleRebind 72 | - event: LOG_CALL(indexed bytes4,indexed address,bytes) 73 | topic0: "0xcf5e7bd300000000000000000000000000000000000000000000000000000000" 74 | handler: handleUnbind 75 | - event: LOG_JOIN(indexed address,indexed address,uint256) 76 | handler: handleJoinPool 77 | - event: LOG_EXIT(indexed address,indexed address,uint256) 78 | handler: handleExitPool 79 | - event: LOG_SWAP(indexed address,indexed address,indexed address,uint256,uint256) 80 | handler: handleSwap 81 | - event: Transfer(indexed address,indexed address,uint256) 82 | handler: handleTransfer 83 | callHandlers: 84 | - function: gulp(address) 85 | handler: handleGulp 86 | - kind: ethereum/contract 87 | name: CrpController 88 | network: mainnet 89 | source: 90 | abi: ConfigurableRightsPool 91 | mapping: 92 | kind: ethereum/events 93 | apiVersion: 0.0.4 94 | language: wasm/assemblyscript 95 | file: ./src/mappings/pool.ts 96 | entities: 97 | - Pool 98 | abis: 99 | - name: ConfigurableRightsPool 100 | file: ./abis/ConfigurableRightsPool.json 101 | eventHandlers: 102 | - event: OwnershipTransferred(indexed address,indexed address) 103 | handler: handleSetCrpController 104 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/@graphprotocol/graph-ts/tsconfig.json", 3 | "compilerOptions": { 4 | "types": ["@graphprotocol/graph-ts"] 5 | } 6 | } 7 | --------------------------------------------------------------------------------