mostly pool stuff

This commit is contained in:
mihaisc 2021-11-19 16:42:17 +02:00
parent dd7710b2f1
commit 3eeba287fb
17 changed files with 6024 additions and 3344 deletions

View File

@ -321,8 +321,8 @@
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b5060405161071938038061071983398101604081905261002f91610207565b6001600160a01b0383166100a05760405162461bcd60e51b815260206004820152602d60248201527f42466163746f72793a20696e76616c69642062706f6f6c2074656d706c61746560448201526c207a65726f206164647265737360981b60648201526084015b60405180910390fd5b6001600160a01b0382166100f65760405162461bcd60e51b815260206004820152601660248201527f42466163746f72793a207a65726f2061646472657373000000000000000000006044820152606401610097565b600080546001600160a01b0319166001600160a01b03841617905561013c836001600160a01b03166000908152600160208190526040909120805460ff19169091179055565b8051156101e35760005b81518110156101e15760006001600160a01b0316336001600160a01b03168383815181106101765761017661031f565b602090810291909101810151604080516000808252938101849052908101929092526001600160a01b0316907fbb6121447d29a04cc37bfd93cdf6a9dd08229f2d941116c1528f04698c4e790e9060600160405180910390a4806101d9816102f6565b915050610146565b505b50505061034b565b80516001600160a01b038116811461020257600080fd5b919050565b60008060006060848603121561021c57600080fd5b610225846101eb565b925060206102348186016101eb565b60408601519093506001600160401b038082111561025157600080fd5b818701915087601f83011261026557600080fd5b81518181111561027757610277610335565b8060051b604051601f19603f8301168101818110858211171561029c5761029c610335565b604052828152858101935084860182860187018c10156102bb57600080fd5b600095505b838610156102e5576102d1816101eb565b8552600195909501949386019386016102c0565b508096505050505050509250925092565b600060001982141561031857634e487b7160e01b600052601160045260246000fd5b5060010190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6103bf8061035a6000396000f3fe608060405234801561001057600080fd5b50600436106101165760003560e01c8063b7b800a4116100a2578063c07c00fe11610071578063c07c00fe146101b8578063c36596a61461013e578063c6580d12146101f4578063e4a28a521461011b578063ec093021146101fc57600080fd5b8063b7b800a414610198578063ba019dab146101a0578063bc063e1a146101a8578063bc694ea2146101b057600080fd5b8063867378c5116100e9578063867378c5146101555780639381cd2b1461015d578063992e2a9214610165578063a28f78f11461016d578063b0e0d1361461019857600080fd5b806309a3bbe41461011b578063189d00ca14610136578063218b53821461013e57806376c7a3c71461014d575b600080fd5b610123610204565b6040519081526020015b60405180910390f35b61012361021a565b610123670de0b6b3a764000081565b610123610231565b610123610246565b61012361025d565b610123610270565b600054610180906001600160a01b031681565b6040516001600160a01b03909116815260200161012d565b610123600281565b610123600181565b61012361028e565b6101236102a1565b6101e46101c63660046102d3565b6001600160a01b031660009081526001602052604090205460ff1690565b604051901515815260200161012d565b610123600081565b6101236102c0565b610217670de0b6b3a7640000603261033d565b81565b6102176402540be400670de0b6b3a764000061031b565b610217620f4240670de0b6b3a764000061031b565b61021764e8d4a51000670de0b6b3a764000061031b565b610217670de0b6b3a7640000606461033d565b6102836003670de0b6b3a764000061031b565b610217906001610303565b610217600a670de0b6b3a764000061031b565b60016102b6670de0b6b3a7640000600261033d565b610217919061035c565b6102176002670de0b6b3a764000061031b565b6000602082840312156102e557600080fd5b81356001600160a01b03811681146102fc57600080fd5b9392505050565b6000821982111561031657610316610373565b500190565b60008261033857634e487b7160e01b600052601260045260246000fd5b500490565b600081600019048311821515161561035757610357610373565b500290565b60008282101561036e5761036e610373565b500390565b634e487b7160e01b600052601160045260246000fdfea264697066735822122051baecb88b2e3924258c058b6adf28c8a64ed8675ac122a5a6e5e1267dbdf04f64736f6c63430008070033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101165760003560e01c8063b7b800a4116100a2578063c07c00fe11610071578063c07c00fe146101b8578063c36596a61461013e578063c6580d12146101f4578063e4a28a521461011b578063ec093021146101fc57600080fd5b8063b7b800a414610198578063ba019dab146101a0578063bc063e1a146101a8578063bc694ea2146101b057600080fd5b8063867378c5116100e9578063867378c5146101555780639381cd2b1461015d578063992e2a9214610165578063a28f78f11461016d578063b0e0d1361461019857600080fd5b806309a3bbe41461011b578063189d00ca14610136578063218b53821461013e57806376c7a3c71461014d575b600080fd5b610123610204565b6040519081526020015b60405180910390f35b61012361021a565b610123670de0b6b3a764000081565b610123610231565b610123610246565b61012361025d565b610123610270565b600054610180906001600160a01b031681565b6040516001600160a01b03909116815260200161012d565b610123600281565b610123600181565b61012361028e565b6101236102a1565b6101e46101c63660046102d3565b6001600160a01b031660009081526001602052604090205460ff1690565b604051901515815260200161012d565b610123600081565b6101236102c0565b610217670de0b6b3a7640000603261033d565b81565b6102176402540be400670de0b6b3a764000061031b565b610217620f4240670de0b6b3a764000061031b565b61021764e8d4a51000670de0b6b3a764000061031b565b610217670de0b6b3a7640000606461033d565b6102836003670de0b6b3a764000061031b565b610217906001610303565b610217600a670de0b6b3a764000061031b565b60016102b6670de0b6b3a7640000600261033d565b610217919061035c565b6102176002670de0b6b3a764000061031b565b6000602082840312156102e557600080fd5b81356001600160a01b03811681146102fc57600080fd5b9392505050565b6000821982111561031657610316610373565b500190565b60008261033857634e487b7160e01b600052601260045260246000fd5b500490565b600081600019048311821515161561035757610357610373565b500290565b60008282101561036e5761036e610373565b500390565b634e487b7160e01b600052601160045260246000fdfea264697066735822122051baecb88b2e3924258c058b6adf28c8a64ed8675ac122a5a6e5e1267dbdf04f64736f6c63430008070033",
"bytecode": "0x608060405234801561001057600080fd5b5060405161071938038061071983398101604081905261002f91610207565b6001600160a01b0383166100a05760405162461bcd60e51b815260206004820152602d60248201527f42466163746f72793a20696e76616c69642062706f6f6c2074656d706c61746560448201526c207a65726f206164647265737360981b60648201526084015b60405180910390fd5b6001600160a01b0382166100f65760405162461bcd60e51b815260206004820152601660248201527f42466163746f72793a207a65726f2061646472657373000000000000000000006044820152606401610097565b600080546001600160a01b0319166001600160a01b03841617905561013c836001600160a01b03166000908152600160208190526040909120805460ff19169091179055565b8051156101e35760005b81518110156101e15760006001600160a01b0316336001600160a01b03168383815181106101765761017661031f565b602090810291909101810151604080516000808252938101849052908101929092526001600160a01b0316907fbb6121447d29a04cc37bfd93cdf6a9dd08229f2d941116c1528f04698c4e790e9060600160405180910390a4806101d9816102f6565b915050610146565b505b50505061034b565b80516001600160a01b038116811461020257600080fd5b919050565b60008060006060848603121561021c57600080fd5b610225846101eb565b925060206102348186016101eb565b60408601519093506001600160401b038082111561025157600080fd5b818701915087601f83011261026557600080fd5b81518181111561027757610277610335565b8060051b604051601f19603f8301168101818110858211171561029c5761029c610335565b604052828152858101935084860182860187018c10156102bb57600080fd5b600095505b838610156102e5576102d1816101eb565b8552600195909501949386019386016102c0565b508096505050505050509250925092565b600060001982141561031857634e487b7160e01b600052601160045260246000fd5b5060010190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6103bf8061035a6000396000f3fe608060405234801561001057600080fd5b50600436106101165760003560e01c8063b7b800a4116100a2578063c07c00fe11610071578063c07c00fe146101b8578063c36596a61461013e578063c6580d12146101f4578063e4a28a521461011b578063ec093021146101fc57600080fd5b8063b7b800a414610198578063ba019dab146101a0578063bc063e1a146101a8578063bc694ea2146101b057600080fd5b8063867378c5116100e9578063867378c5146101555780639381cd2b1461015d578063992e2a9214610165578063a28f78f11461016d578063b0e0d1361461019857600080fd5b806309a3bbe41461011b578063189d00ca14610136578063218b53821461013e57806376c7a3c71461014d575b600080fd5b610123610204565b6040519081526020015b60405180910390f35b61012361021a565b610123670de0b6b3a764000081565b610123610231565b610123610246565b61012361025d565b610123610270565b600054610180906001600160a01b031681565b6040516001600160a01b03909116815260200161012d565b610123600281565b610123600181565b61012361028e565b6101236102a1565b6101e46101c63660046102d3565b6001600160a01b031660009081526001602052604090205460ff1690565b604051901515815260200161012d565b610123600081565b6101236102c0565b610217670de0b6b3a7640000603261033d565b81565b6102176402540be400670de0b6b3a764000061031b565b610217620f4240670de0b6b3a764000061031b565b61021764e8d4a51000670de0b6b3a764000061031b565b610217670de0b6b3a7640000606461033d565b6102836003670de0b6b3a764000061031b565b610217906001610303565b610217600a670de0b6b3a764000061031b565b60016102b6670de0b6b3a7640000600261033d565b610217919061035c565b6102176002670de0b6b3a764000061031b565b6000602082840312156102e557600080fd5b81356001600160a01b03811681146102fc57600080fd5b9392505050565b6000821982111561031657610316610373565b500190565b60008261033857634e487b7160e01b600052601260045260246000fd5b500490565b600081600019048311821515161561035757610357610373565b500290565b60008282101561036e5761036e610373565b500390565b634e487b7160e01b600052601160045260246000fdfea2646970667358221220f4f9367d9939a8dac54a482bb30fc85ba7649a673baccad6dd6c89f740b79f9f64736f6c63430008070033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101165760003560e01c8063b7b800a4116100a2578063c07c00fe11610071578063c07c00fe146101b8578063c36596a61461013e578063c6580d12146101f4578063e4a28a521461011b578063ec093021146101fc57600080fd5b8063b7b800a414610198578063ba019dab146101a0578063bc063e1a146101a8578063bc694ea2146101b057600080fd5b8063867378c5116100e9578063867378c5146101555780639381cd2b1461015d578063992e2a9214610165578063a28f78f11461016d578063b0e0d1361461019857600080fd5b806309a3bbe41461011b578063189d00ca14610136578063218b53821461013e57806376c7a3c71461014d575b600080fd5b610123610204565b6040519081526020015b60405180910390f35b61012361021a565b610123670de0b6b3a764000081565b610123610231565b610123610246565b61012361025d565b610123610270565b600054610180906001600160a01b031681565b6040516001600160a01b03909116815260200161012d565b610123600281565b610123600181565b61012361028e565b6101236102a1565b6101e46101c63660046102d3565b6001600160a01b031660009081526001602052604090205460ff1690565b604051901515815260200161012d565b610123600081565b6101236102c0565b610217670de0b6b3a7640000603261033d565b81565b6102176402540be400670de0b6b3a764000061031b565b610217620f4240670de0b6b3a764000061031b565b61021764e8d4a51000670de0b6b3a764000061031b565b610217670de0b6b3a7640000606461033d565b6102836003670de0b6b3a764000061031b565b610217906001610303565b610217600a670de0b6b3a764000061031b565b60016102b6670de0b6b3a7640000600261033d565b610217919061035c565b6102176002670de0b6b3a764000061031b565b6000602082840312156102e557600080fd5b81356001600160a01b03811681146102fc57600080fd5b9392505050565b6000821982111561031657610316610373565b500190565b60008261033857634e487b7160e01b600052601260045260246000fd5b500490565b600081600019048311821515161561035757610357610373565b500290565b60008282101561036e5761036e610373565b500390565b634e487b7160e01b600052601160045260246000fdfea2646970667358221220f4f9367d9939a8dac54a482bb30fc85ba7649a673baccad6dd6c89f740b79f9f64736f6c63430008070033",
"linkReferences": {},
"deployedLinkReferences": {}
}

314
abis/BMath.json Normal file
View File

@ -0,0 +1,314 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "BMath",
"sourceName": "contracts/pools/balancer/BMath.sol",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "swapFeeAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "oceanFeeAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "marketFeeAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "tokenFees",
"type": "address"
}
],
"name": "SWAP_FEES",
"type": "event"
},
{
"inputs": [],
"name": "BONE",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "BPOW_PRECISION",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "EXIT_FEE",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "INIT_POOL_SUPPLY",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MAX_BOUND_TOKENS",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MAX_BPOW_BASE",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MAX_FEE",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MAX_IN_RATIO",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MAX_OUT_RATIO",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MAX_TOTAL_WEIGHT",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MAX_WEIGHT",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MIN_BALANCE",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MIN_BOUND_TOKENS",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MIN_BPOW_BASE",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MIN_FEE",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MIN_WEIGHT",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "_swapMarketFee",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "communityFees",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getOPFFee",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "marketFees",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b50610460806100206000396000f3fe608060405234801561001057600080fd5b506004361061012c5760003560e01c8063992e2a92116100ad578063bc694ea211610071578063bc694ea2146101eb578063c36596a614610153578063c6580d12146101f3578063e4a28a5214610131578063ec093021146101fb57600080fd5b8063992e2a92146101cb578063b0e0d136146101d3578063b7b800a4146101d3578063ba019dab146101db578063bc063e1a146101e357600080fd5b806349e9350f116100f457806349e9350f146101a2578063700dd7e8146101ab57806376c7a3c7146101b3578063867378c5146101bb5780639381cd2b146101c357600080fd5b806309a3bbe414610131578063189d00ca1461014b578063218b538214610153578063300621921461016257806331e2761b14610182575b600080fd5b610139610203565b60405190815260200160405180910390f35b610139610219565b610139670de0b6b3a764000081565b61013961017036600461035b565b60056020526000908152604090205481565b61013961019036600461035b565b60066020526000908152604090205481565b61013960005481565b610139610230565b6101396102b9565b6101396102ce565b6101396102e5565b6101396102f8565b610139600281565b610139600181565b610139610316565b610139610329565b610139600081565b610139610348565b610216670de0b6b3a764000060326103de565b81565b6102166402540be400670de0b6b3a76400006103bc565b60025460048054604051637c0aa57760e11b81526001600160a01b0391821692810192909252600092169063f8154aee9060240160206040518083038186803b15801561027c57600080fd5b505afa158015610290573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102b4919061038b565b905090565b610216620f4240670de0b6b3a76400006103bc565b61021664e8d4a51000670de0b6b3a76400006103bc565b610216670de0b6b3a764000060646103de565b61030b6003670de0b6b3a76400006103bc565b6102169060016103a4565b610216600a670de0b6b3a76400006103bc565b600161033e670de0b6b3a764000060026103de565b61021691906103fd565b6102166002670de0b6b3a76400006103bc565b60006020828403121561036d57600080fd5b81356001600160a01b038116811461038457600080fd5b9392505050565b60006020828403121561039d57600080fd5b5051919050565b600082198211156103b7576103b7610414565b500190565b6000826103d957634e487b7160e01b600052601260045260246000fd5b500490565b60008160001904831182151516156103f8576103f8610414565b500290565b60008282101561040f5761040f610414565b500390565b634e487b7160e01b600052601160045260246000fdfea2646970667358221220699b1f34bf1d54caa297e60d6fddebd8dc902d2243c98d4a62f4485302305a1064736f6c63430008070033",
"deployedBytecode": "0x608060405234801561001057600080fd5b506004361061012c5760003560e01c8063992e2a92116100ad578063bc694ea211610071578063bc694ea2146101eb578063c36596a614610153578063c6580d12146101f3578063e4a28a5214610131578063ec093021146101fb57600080fd5b8063992e2a92146101cb578063b0e0d136146101d3578063b7b800a4146101d3578063ba019dab146101db578063bc063e1a146101e357600080fd5b806349e9350f116100f457806349e9350f146101a2578063700dd7e8146101ab57806376c7a3c7146101b3578063867378c5146101bb5780639381cd2b146101c357600080fd5b806309a3bbe414610131578063189d00ca1461014b578063218b538214610153578063300621921461016257806331e2761b14610182575b600080fd5b610139610203565b60405190815260200160405180910390f35b610139610219565b610139670de0b6b3a764000081565b61013961017036600461035b565b60056020526000908152604090205481565b61013961019036600461035b565b60066020526000908152604090205481565b61013960005481565b610139610230565b6101396102b9565b6101396102ce565b6101396102e5565b6101396102f8565b610139600281565b610139600181565b610139610316565b610139610329565b610139600081565b610139610348565b610216670de0b6b3a764000060326103de565b81565b6102166402540be400670de0b6b3a76400006103bc565b60025460048054604051637c0aa57760e11b81526001600160a01b0391821692810192909252600092169063f8154aee9060240160206040518083038186803b15801561027c57600080fd5b505afa158015610290573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102b4919061038b565b905090565b610216620f4240670de0b6b3a76400006103bc565b61021664e8d4a51000670de0b6b3a76400006103bc565b610216670de0b6b3a764000060646103de565b61030b6003670de0b6b3a76400006103bc565b6102169060016103a4565b610216600a670de0b6b3a76400006103bc565b600161033e670de0b6b3a764000060026103de565b61021691906103fd565b6102166002670de0b6b3a76400006103bc565b60006020828403121561036d57600080fd5b81356001600160a01b038116811461038457600080fd5b9392505050565b60006020828403121561039d57600080fd5b5051919050565b600082198211156103b7576103b7610414565b500190565b6000826103d957634e487b7160e01b600052601260045260246000fd5b500490565b60008160001904831182151516156103f8576103f8610414565b500290565b60008282101561040f5761040f610414565b500390565b634e487b7160e01b600052601160045260246000fdfea2646970667358221220699b1f34bf1d54caa297e60d6fddebd8dc902d2243c98d4a62f4485302305a1064736f6c63430008070033",
"linkReferences": {},
"deployedLinkReferences": {}
}

File diff suppressed because one or more lines are too long

489
abis/BToken.json Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1470
abis/ERC721Template.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,4 @@
type Token @entity {
id: ID!
symbol: String
name: String
@ -82,8 +81,6 @@ type Pool @entity {
id: ID!
"owner address, pool controller"
owner: String!
"if swap/trade is activated, probably always true"
isPublicSwap: Boolean!
"only finalized pools are relevant to us"
isFinalized: Boolean!
@ -93,8 +90,6 @@ type Pool @entity {
name: String
"maximum supply if any, converted from wei"
cap: BigDecimal
"pool is active"
isActive: Boolean!
baseToken: PoolToken!
datatoken: PoolToken!
@ -140,7 +135,7 @@ type Pool @entity {
"block number when it was created"
block: Int
shares: [PoolShare!] @derivedFrom(field: "pool")
shares: [PoolShares!] @derivedFrom(field: "pool")
transactions: [PoolTransaction!] @derivedFrom(field: "pool")
}
@ -157,12 +152,12 @@ type PoolToken @entity {
}
# we will need to track pool share tx between users - bpool transfer tx event
type PoolShare @entity {
type PoolShares @entity {
"poolAddress + userAddress"
id: ID!
user: User!
pool: Pool!
balance: BigDecimal!
shares: BigDecimal!
}
enum PoolTransactionType {
@ -200,11 +195,14 @@ type PoolTransaction @entity {
"price expressed in eth"
gasPrice: BigDecimal!
# change to baseToken and dataToken
"base tokens transfered , if value is negative it means it was removed"
"base tokens transfered"
baseToken: TokenValuePair
"number of tokens transfered"
baseTokenValue: BigDecimal
"datatokens transfered , if value is negative it means it was removed"
datatoken: TokenValuePair
"number of tokens transfered, if value is negative it means it was removed"
datatokenValue: BigDecimal
}
type Order @entity { # renamed from TokenOrder to Order
@ -247,7 +245,7 @@ type TokenTransaction @entity {
type User @entity {
id: ID!
sharesOwned: [PoolShare!] @derivedFrom(field: "user")
sharesOwned: [PoolShares!] @derivedFrom(field: "user")
tokenBalancesOwned: [TokenValuePair!]
tokensOwned: [Token!] @derivedFrom(field: "minter")
poolTransactions: [PoolTransaction!] @derivedFrom(field: "user")
@ -363,7 +361,7 @@ type PoolSnapshotTokenValue @entity {
poolSnapshot: PoolSnapshot!
}
type Global @entity {
type GlobalStats @entity {
id: ID!
"total value locked represented in the base token , basically 2x liqudity for each base token"

View File

@ -60,6 +60,6 @@ export function handleTokensDispensed(event: TokensDispensed): void {
export function handleOwnerWinthdraw(event: OwnerWithdrawed): void {
const dispenser = getDispenser(event.params.datatoken.toHex())
dispenser.balance = decimal.ZERO_BD
dispenser.balance = decimal.ZERO
dispenser.save()
}

View File

@ -9,7 +9,7 @@ export function handleNftCreated(event: NFTCreated): void {
const user = getUser(event.params.admin.toHexString())
nft.owner = user.id
nft.address = event.params.newTokenAddress.toHexString()
nft.name = event.params.tokenName.toHex()
nft.name = event.params.tokenName
nft.symbol = ''
nft.createdTimestamp = event.block.timestamp.toI32()
nft.tx = event.transaction.hash
@ -26,8 +26,8 @@ export function handleNewToken(event: TokenCreated): void {
token.tx = event.transaction.hash
token.block = event.block.number.toI32()
token.name = event.params.tokenName.toString()
token.name = event.params.name
token.decimals = 18
token.supply = decimal.ZERO_BD
token.supply = decimal.ZERO
token.save()
}

View File

@ -14,7 +14,7 @@ import {
FixedRateExchangeUpdate
} from '../@types/schema'
import { getFixedRateExchange, getUpdateOrSwapId } from './utils/fixedRateUtils'
import { tokenToDecimal } from './utils/generic'
import { weiToDecimal } from './utils/generic'
import { getToken } from './utils/tokenUtils'
import { getUser } from './utils/userUtils'
@ -29,7 +29,7 @@ export function handleExchangeCreated(event: ExchangeCreated): void {
// fixedRateExchange.baseTokenSymbol = getTokenSymbol(event.params.baseToken)
fixedRateExchange.active = false
fixedRateExchange.price = tokenToDecimal(
fixedRateExchange.price = weiToDecimal(
event.params.fixedRate.toBigDecimal(),
BigInt.fromI32(18).toI32()
)
@ -51,7 +51,7 @@ export function handleRateChange(event: ExchangeRateChanged): void {
newExchangeUpdate.tx = event.transaction.hash
newExchangeUpdate.block = event.block.number.toI32()
fixedRateExchange.price = tokenToDecimal(
fixedRateExchange.price = weiToDecimal(
event.params.newRate.toBigDecimal(),
BigInt.fromI32(18).toI32()
)
@ -166,11 +166,11 @@ export function handleSwap(event: Swapped): void {
// we need to fetch the decimals of the base token
const baseToken = getToken(fixedRateExchange.baseToken)
swap.baseTokenAmount = tokenToDecimal(
swap.baseTokenAmount = weiToDecimal(
event.params.baseTokenSwappedAmount.toBigDecimal(),
BigInt.fromI32(baseToken.decimals).toI32()
)
swap.dataTokenAmount = tokenToDecimal(
swap.dataTokenAmount = weiToDecimal(
event.params.dataTokenSwappedAmount.toBigDecimal(),
BigInt.fromI32(18).toI32()
)

View File

@ -1,30 +1,214 @@
import { Pool, PoolTransaction } from '../@types/schema'
import { LOG_JOIN } from '../@types/templates/BPool/BPool'
import { integer } from './utils/constants'
import { gweiToEth } from './utils/generic'
import { PoolTransaction } from '../@types/schema'
import {
LOG_BPT,
LOG_EXIT,
LOG_JOIN,
LOG_SETUP,
LOG_SWAP
} from '../@types/templates/BPool/BPool'
import { Transfer } from '../@types/templates/BPool/BToken'
import { integer, PoolTransactionType } from './utils/constants'
import { weiToDecimal } from './utils/generic'
import {
calcSpotPrice,
getPool,
getPoolToken,
getPoolTransaction,
getPoolShares
} from './utils/poolUtils'
import { getToken } from './utils/tokenUtils'
import { getUser } from './utils/userUtils'
// kinda redundant code in join/swap/exit
export function handleJoin(event: LOG_JOIN): void {
const pool = Pool.load(event.address.toHex())
// should we do something else here?
if (pool === null || pool.isFinalized === true) return
const pool = getPool(event.address.toHex())
const user = getUser(event.params.caller.toHex())
const poolTx = getPoolTransaction(event, user.id, PoolTransactionType.JOIN)
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
pool.joinCount = pool.joinCount.plus(integer.ONE)
const poolTx = new PoolTransaction(event.transaction.hash.toHex())
const user = getUser(event.params.caller.toHex())
poolTx.user = user.id
poolTx.pool = pool.id
// get token, update pool transaction and update pool user liquidity
const token = getToken(event.params.tokenIn.toHex())
const ammount = weiToDecimal(
event.params.tokenAmountIn.toBigDecimal(),
token.decimals
)
if (token.isDatatoken) {
poolTx.datatoken = token.id
poolTx.datatokenValue = ammount
} else {
poolTx.baseToken = token.id
poolTx.baseTokenValue = ammount
}
poolTx.timestamp = event.block.timestamp.toI32()
poolTx.tx = event.transaction.hash
poolTx.block = event.block.number.toI32()
poolTx.gasPrice = gweiToEth(event.transaction.gasPrice.toBigDecimal())
poolTx.gasLimit = event.transaction.gasLimit.toBigDecimal()
// update pool token
const poolToken = getPoolToken(pool.id, token.id)
poolToken.balance.plus(ammount)
poolToken.save()
poolTx.save()
pool.save()
}
export function handleExit(event: LOG_EXIT): void {
const pool = getPool(event.address.toHex())
const user = getUser(event.params.caller.toHex())
const poolTx = getPoolTransaction(event, user.id, PoolTransactionType.EXIT)
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
pool.joinCount = pool.joinCount.plus(integer.ONE)
// get token and update pool transaction, value is negative because this is an exit event.
const token = getToken(event.params.tokenOut.toHex())
const ammount = weiToDecimal(
event.params.tokenAmountOut.toBigDecimal(),
token.decimals
)
if (token.isDatatoken) {
poolTx.datatoken = token.id
poolTx.datatokenValue = ammount.neg()
} else {
poolTx.baseToken = token.id
poolTx.baseTokenValue = ammount.neg()
}
const poolToken = getPoolToken(pool.id, token.id)
poolToken.balance.minus(ammount)
poolToken.save()
poolTx.save()
pool.save()
}
export function handleSwap(event: LOG_SWAP): void {
const pool = getPool(event.address.toHex())
const user = getUser(event.params.caller.toHex())
const poolTx = getPoolTransaction(event, user.id, PoolTransactionType.SWAP)
pool.transactionCount = pool.transactionCount.plus(integer.ONE)
pool.joinCount = pool.joinCount.plus(integer.ONE)
// get token out and update pool transaction, value is negative
const tokenOut = getToken(event.params.tokenOut.toHex())
const ammountOut = weiToDecimal(
event.params.tokenAmountOut.toBigDecimal(),
tokenOut.decimals
)
if (tokenOut.isDatatoken) {
poolTx.datatoken = tokenOut.id
poolTx.datatokenValue = ammountOut.neg()
} else {
poolTx.baseToken = tokenOut.id
poolTx.baseTokenValue = ammountOut.neg()
}
const poolTokenOut = getPoolToken(pool.id, tokenOut.id)
poolTokenOut.balance.minus(ammountOut)
// update pool token in
const tokenIn = getToken(event.params.tokenIn.toHex())
const ammountIn = weiToDecimal(
event.params.tokenAmountIn.toBigDecimal(),
tokenIn.decimals
)
if (tokenIn.isDatatoken) {
poolTx.datatoken = tokenIn.id
poolTx.datatokenValue = ammountIn
} else {
poolTx.baseToken = tokenIn.id
poolTx.baseTokenValue = ammountIn
}
const poolTokenIn = getPoolToken(pool.id, tokenIn.id)
poolTokenIn.balance.plus(ammountIn)
// update spot price
const isTokenInDatatoken = tokenIn.isDatatoken
const spotPrice = calcSpotPrice(
pool.id,
isTokenInDatatoken ? tokenOut.id : tokenIn.id,
isTokenInDatatoken ? tokenIn.id : tokenOut.id,
isTokenInDatatoken ? tokenIn.decimals : tokenOut.decimals
)
pool.spotPrice = spotPrice
poolTokenIn.save()
poolTokenOut.save()
poolTx.save()
pool.save()
}
// setup is just to set token weight and spotPrice , it will mostly be 50:50
export function handleSetup(event: LOG_SETUP): void {
const pool = getPool(event.address.toHex())
const token = getToken(event.params.baseToken.toHex())
const baseToken = getPoolToken(pool.id, event.params.baseToken.toHex())
baseToken.denormWeight = weiToDecimal(
event.params.baseTokenWeight.toBigDecimal(),
token.decimals
)
baseToken.save()
// decimals hardcoded because datatokens have 18 decimals
const datatoken = getPoolToken(pool.id, event.params.dataToken.toHex())
datatoken.denormWeight = weiToDecimal(
event.params.dataTokenWeight.toBigDecimal(),
18
)
// calculate spotPrice
const spotPrice = calcSpotPrice(
pool.id,
pool.baseToken,
pool.datatoken,
token.decimals
)
pool.spotPrice = spotPrice
pool.isFinalized = true
pool.save()
datatoken.save()
}
export function handleBpt(event: LOG_BPT): void {
const pool = getPool(event.address.toHex())
const poolShares = getPoolShares(pool.id, event.transaction.from.toHex())
const poolTx = PoolTransaction.load(event.transaction.hash.toHex())
// TODO: should we return here if null? theoretically this should not be null since LOG_BPT is after the other events
if (!poolTx) return
const decimalBpt = weiToDecimal(event.params.bptAmount.toBigDecimal(), 18)
switch (poolTx.type) {
case PoolTransactionType.JOIN: {
poolShares.shares = poolShares.shares.plus(decimalBpt)
pool.totalShares.plus(decimalBpt)
break
}
case PoolTransactionType.EXIT: {
poolShares.shares = poolShares.shares.minus(decimalBpt)
pool.totalShares.minus(decimalBpt)
break
}
}
poolShares.shares = weiToDecimal(event.params.bptAmount.toBigDecimal(), 18)
pool.save()
poolShares.save()
}
export function handlerBptTransfer(event: Transfer): void {
const fromUser = getPoolShares(
event.address.toHex(),
event.params.src.toHex()
)
const toUser = getPoolShares(event.address.toHex(), event.params.dst.toHex())
const ammount = weiToDecimal(event.params.amt.toBigDecimal(), 18)
fromUser.shares = fromUser.shares.minus(ammount)
toUser.shares = toUser.shares.plus(ammount)
fromUser.save()
toUser.save()
}

View File

@ -11,8 +11,15 @@ export namespace integer {
}
export namespace decimal {
export const ZERO_BD = BigDecimal.fromString('0.0')
export const MINUS_1_BD = BigDecimal.fromString('-1.0')
export const ONE_BD = BigDecimal.fromString('1.0')
export const ZERO = BigDecimal.fromString('0.0')
export const MINUS_1 = BigDecimal.fromString('-1.0')
export const ONE = BigDecimal.fromString('1.0')
export const BONE = BigDecimal.fromString('1000000000000000000')
}
export enum PoolTransactionType {
JOIN = 'JOIN',
EXIT = 'EXIT',
SWAP = 'SWAP',
SETUP = 'SETUP'
}

View File

@ -26,7 +26,7 @@ export function getOceanAddress(): string {
export const OCEAN: string = getOceanAddress()
export function tokenToDecimal(amount: BigDecimal, decimals: i32): BigDecimal {
export function weiToDecimal(amount: BigDecimal, decimals: i32): BigDecimal {
const scale = BigInt.fromI32(10)
.pow(decimals as u8)
.toBigDecimal()

View File

@ -0,0 +1,3 @@
const GLOBAL_ID = 1
export function getGlobalStats(): void {}

View File

@ -1,4 +1,66 @@
import { PoolToken } from '../../@types/schema'
import { Address, BigDecimal, ethereum } from '@graphprotocol/graph-ts'
import {
Pool,
PoolShares,
PoolToken,
PoolTransaction
} from '../../@types/schema'
import { BPool } from '../../@types/templates/BPool/BPool'
import { PoolTransactionType } from './constants'
import { gweiToEth, weiToDecimal } from './generic'
export function getPoolSharesId(
poolAddress: string,
userAddress: string
): string {
return `${poolAddress}-${userAddress}`
}
export function getPoolTransaction(
event: ethereum.Event,
userAddress: string,
type: PoolTransactionType
): PoolTransaction {
let poolTx = PoolTransaction.load(event.transaction.hash.toHex())
// create pool transaction and fill basic fields
if (poolTx === null) {
poolTx = new PoolTransaction(event.transaction.hash.toHex())
poolTx.user = userAddress
poolTx.pool = event.address.toHex()
poolTx.type = type
poolTx.timestamp = event.block.timestamp.toI32()
poolTx.tx = event.transaction.hash
poolTx.block = event.block.number.toI32()
poolTx.gasPrice = gweiToEth(event.transaction.gasPrice.toBigDecimal())
poolTx.gasLimit = event.transaction.gasLimit.toBigDecimal()
}
return poolTx
}
export function getPoolShares(
poolAddress: string,
userAddress: string
): PoolShares {
let poolShares = PoolShares.load(getPoolSharesId(poolAddress, userAddress))
if (poolShares === null) {
poolShares = new PoolShares(getPoolSharesId(poolAddress, userAddress))
}
return poolShares
}
export function getPool(poolAddress: string): Pool {
const pool = Pool.load(poolAddress)
if (pool === null) {
// what now?
throw new Error(`Didn't find pool with address ${poolAddress} `)
}
return pool
}
export function getPoolTokenId(
poolAddress: string,
@ -19,3 +81,20 @@ export function getPoolToken(
return poolToken
}
export function calcSpotPrice(
poolAddress: string,
baseTokenAddress: string,
datatokenAddress: string,
baseTokenDecimals: i32
): BigDecimal {
const poolContract = BPool.bind(Address.fromString(poolAddress))
// tokenIn is always the baseToken and tokenOut is the datatoken because we want the spot price to be in baseToken eg: 1 DT = 0.5 OCEAN
const weiPrice = poolContract.try_getSpotPrice(
Address.fromString(baseTokenAddress),
Address.fromString(datatokenAddress)
).reverted
const price = weiToDecimal(weiPrice, baseTokenDecimals)
return price
}

View File

@ -22,9 +22,9 @@ dataSources:
- name: ERC721Factory
file: ./abis/ERC721Factory.json
eventHandlers:
- event: NFTCreated(indexed address,indexed address,indexed string,address)
- event: NFTCreated(indexed address,indexed address,string,address,string,string)
handler: handleNftCreated
- event: TokenCreated(indexed address,indexed address,indexed string)
- event: TokenCreated(indexed address,indexed address,string,string,uint256,address)
handler: handleNewToken
- kind: ethereum/contract
name: FixedRateExchange
@ -76,7 +76,7 @@ dataSources:
- name: Dispenser
file: ./abis/Dispenser.json
eventHandlers:
- event: DispenserCreated(indexed address)
- event: DispenserCreated(indexed address,indexed address,uint256,uint256,address)
handler: handleNewDispenser
- event: DispenserActivated(indexed address)
handler: handleActivate
@ -156,6 +156,8 @@ templates:
abis:
- name: BPool
file: ./abis/BPool.json
- name: BToken
file: ./abis/BToken.json
eventHandlers:
- event: LOG_SWAP(indexed address,indexed address,indexed address,uint256,uint256,uint256)
handler: handleSwap
@ -163,5 +165,12 @@ templates:
handler: handleJoin
- event: LOG_EXIT(indexed address,indexed address,uint256,uint256)
handler: handleExit
- event: LOG_SETUP(indexed address,indexed address,uint256,uint256,indexed address,uint256,uint256)
handler: handleSetup
- event: LOG_BPT(uint256)
handler: handleBpt
- event: Transfer(indexed address,indexed address,uint256)
handler: handlerBptTransfer
features:
- nonFatalErrors