diff --git a/pkg/liquidity-source/balancer-v2/shared/pools_list_updater.go b/pkg/liquidity-source/balancer-v2/shared/pools_list_updater.go index cce22affb..45d309aef 100644 --- a/pkg/liquidity-source/balancer-v2/shared/pools_list_updater.go +++ b/pkg/liquidity-source/balancer-v2/shared/pools_list_updater.go @@ -2,11 +2,11 @@ package shared import ( "context" - "encoding/json" "math/big" "time" graphqlpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/graphql" + "github.com/goccy/go-json" "github.com/machinebox/graphql" ) diff --git a/pkg/liquidity-source/gravity/abis.go b/pkg/liquidity-source/gravity/abis.go new file mode 100644 index 000000000..349d0cf49 --- /dev/null +++ b/pkg/liquidity-source/gravity/abis.go @@ -0,0 +1,34 @@ +package gravity + +import ( + "bytes" + + "github.com/ethereum/go-ethereum/accounts/abi" +) + +var ( + uniswapV2PairABI abi.ABI + uniswapV2FactoryABI abi.ABI +) + +func init() { + builder := []struct { + ABI *abi.ABI + data []byte + }{ + { + &uniswapV2PairABI, pairABIJson, + }, + { + &uniswapV2FactoryABI, factoryABIJson, + }, + } + + for _, b := range builder { + var err error + *b.ABI, err = abi.JSON(bytes.NewReader(b.data)) + if err != nil { + panic(err) + } + } +} diff --git a/pkg/liquidity-source/gravity/abis/UniswapV2Factory.json b/pkg/liquidity-source/gravity/abis/UniswapV2Factory.json new file mode 100644 index 000000000..a2f132767 --- /dev/null +++ b/pkg/liquidity-source/gravity/abis/UniswapV2Factory.json @@ -0,0 +1,193 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "_feeToSetter", + "type": "address" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "pair", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "PairCreated", + "type": "event" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "allPairs", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "allPairsLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenB", + "type": "address" + } + ], + "name": "createPair", + "outputs": [ + { + "internalType": "address", + "name": "pair", + "type": "address" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "feeTo", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "feeToSetter", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "getPair", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "_feeTo", + "type": "address" + } + ], + "name": "setFeeTo", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "_feeToSetter", + "type": "address" + } + ], + "name": "setFeeToSetter", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/pkg/liquidity-source/gravity/abis/UniswapV2Pair.json b/pkg/liquidity-source/gravity/abis/UniswapV2Pair.json new file mode 100644 index 000000000..53582c1ed --- /dev/null +++ b/pkg/liquidity-source/gravity/abis/UniswapV2Pair.json @@ -0,0 +1,713 @@ +[ + { + "inputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "Burn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0In", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1In", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0Out", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1Out", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "Swap", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint112", + "name": "reserve0", + "type": "uint112" + }, + { + "indexed": false, + "internalType": "uint112", + "name": "reserve1", + "type": "uint112" + } + ], + "name": "Sync", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MINIMUM_LIQUIDITY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "PERMIT_TYPEHASH", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "burn", + "outputs": [ + { + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "factory", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getReserves", + "outputs": [ + { + "internalType": "uint112", + "name": "_reserve0", + "type": "uint112" + }, + { + "internalType": "uint112", + "name": "_reserve1", + "type": "uint112" + }, + { + "internalType": "uint32", + "name": "_blockTimestampLast", + "type": "uint32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "_token0", + "type": "address" + }, + { + "internalType": "address", + "name": "_token1", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "kLast", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "nonces", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "permit", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "price0CumulativeLast", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "price1CumulativeLast", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "skim", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "amount0Out", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1Out", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "swap", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "sync", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "token0", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "token1", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/pkg/liquidity-source/gravity/config.go b/pkg/liquidity-source/gravity/config.go new file mode 100644 index 000000000..5986977c5 --- /dev/null +++ b/pkg/liquidity-source/gravity/config.go @@ -0,0 +1,7 @@ +package gravity + +type Config struct { + DexID string `json:"dexID"` + FactoryAddress string `json:"factoryAddress"` + NewPoolLimit int `json:"newPoolLimit"` +} diff --git a/pkg/liquidity-source/gravity/constant.go b/pkg/liquidity-source/gravity/constant.go new file mode 100644 index 000000000..12e0c9632 --- /dev/null +++ b/pkg/liquidity-source/gravity/constant.go @@ -0,0 +1,20 @@ +package gravity + +const ( + DexType = "uniswap-v2" +) + +var ( + defaultGas = Gas{Swap: 60000} +) + +const ( + factoryMethodGetPair = "allPairs" + factoryMethodAllPairsLength = "allPairsLength" +) + +const ( + pairMethodToken0 = "token0" + pairMethodToken1 = "token1" + pairMethodGetReserves = "getReserves" +) diff --git a/pkg/liquidity-source/gravity/embed.go b/pkg/liquidity-source/gravity/embed.go new file mode 100644 index 000000000..d7998240e --- /dev/null +++ b/pkg/liquidity-source/gravity/embed.go @@ -0,0 +1,9 @@ +package gravity + +import _ "embed" + +//go:embed abis/UniswapV2Pair.json +var pairABIJson []byte + +//go:embed abis/UniswapV2Factory.json +var factoryABIJson []byte diff --git a/pkg/liquidity-source/gravity/log_decoder.go b/pkg/liquidity-source/gravity/log_decoder.go new file mode 100644 index 000000000..d301cf4ca --- /dev/null +++ b/pkg/liquidity-source/gravity/log_decoder.go @@ -0,0 +1,65 @@ +package gravity + +import ( + "math/big" + + "github.com/ethereum/go-ethereum/core/types" +) + +type LogDecoder struct{} + +func NewLogDecoder() *LogDecoder { + return &LogDecoder{} +} + +func (d *LogDecoder) Decode(logs []types.Log) (ReserveData, *big.Int, error) { + latestSyncEvent := d.findLatestSyncEvent(logs) + + if len(latestSyncEvent.Data) == 0 { + return ReserveData{}, nil + } + + filterer, err := NewUniswapFilterer(latestSyncEvent.Address, nil) + if err != nil { + return ReserveData{}, nil, err + } + + syncEvent, err := filterer.ParseSync(latestSyncEvent) + if err != nil { + return ReserveData{}, nil, err + } + + return ReserveData{ + Reserve0: syncEvent.Reserve0, + Reserve1: syncEvent.Reserve1, + }, new(big.Int).SetUint64(syncEvent.Raw.BlockNumber), nil +} + +func (d *LogDecoder) findLatestSyncEvent(logs []types.Log) types.Log { + var latestEvent types.Log + + for _, log := range logs { + if log.Removed { + continue + } + + if !d.isSyncEvent(log) { + continue + } + + if latestEvent.BlockNumber < log.BlockNumber || (latestEvent.BlockNumber == log.BlockNumber && latestEvent.Index < log.Index) { + latestEvent = log + } + } + + return latestEvent +} + +// isSyncEvent returns true if the first topic is a uniswap-v2 sync event +func (d *LogDecoder) isSyncEvent(log types.Log) bool { + if len(log.Topics) == 0 { + return false + } + + return log.Topics[0] == uniswapV2PairABI.Events["Sync"].ID +} diff --git a/pkg/liquidity-source/gravity/pool_list_updater.go b/pkg/liquidity-source/gravity/pool_list_updater.go new file mode 100644 index 000000000..dfaa44cdb --- /dev/null +++ b/pkg/liquidity-source/gravity/pool_list_updater.go @@ -0,0 +1,271 @@ +package gravity + +import ( + "context" + "math/big" + "strings" + "time" + + "github.com/KyberNetwork/ethrpc" + "github.com/KyberNetwork/logger" + "github.com/ethereum/go-ethereum/common" + "github.com/goccy/go-json" + + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util" +) + +type ( + PoolsListUpdater struct { + config *Config + ethrpcClient *ethrpc.Client + } + + PoolsListUpdaterMetadata struct { + Offset int `json:"offset"` + } +) + +func NewPoolsListUpdater( + cfg *Config, + ethrpcClient *ethrpc.Client, +) *PoolsListUpdater { + return &PoolsListUpdater{ + config: cfg, + ethrpcClient: ethrpcClient, + } +} + +func (u *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte) ([]entity.Pool, []byte, error) { + var ( + dexID = u.config.DexID + startTime = time.Now() + ) + + logger.WithFields(logger.Fields{"dex_id": dexID}).Info("Started getting new pools") + + ctx = util.NewContextWithTimestamp(ctx) + + allPairsLength, err := u.getAllPairsLength(ctx) + if err != nil { + logger. + WithFields(logger.Fields{"dex_id": dexID}). + Error("getAllPairsLength failed") + + return nil, metadataBytes, err + } + + offset, err := u.getOffset(metadataBytes) + if err != nil { + logger. + WithFields(logger.Fields{"dex_id": dexID, "err": err}). + Warn("getOffset failed") + } + + batchSize := getBatchSize(allPairsLength, u.config.NewPoolLimit, offset) + + pairAddresses, err := u.listPairAddresses(ctx, offset, batchSize) + if err != nil { + logger. + WithFields(logger.Fields{"dex_id": dexID, "err": err}). + Error("listPairAddresses failed") + + return nil, metadataBytes, err + } + + pools, err := u.initPools(ctx, pairAddresses) + if err != nil { + logger. + WithFields(logger.Fields{"dex_id": dexID, "err": err}). + Error("initPools failed") + + return nil, metadataBytes, err + } + + newMetadataBytes, err := u.newMetadata(offset + batchSize) + if err != nil { + logger. + WithFields(logger.Fields{"dex_id": dexID, "err": err}). + Error("newMetadata failed") + + return nil, metadataBytes, err + } + + logger. + WithFields( + logger.Fields{ + "dex_id": dexID, + "pools_len": len(pools), + "offset": offset, + "duration_ms": time.Since(startTime).Milliseconds(), + }, + ). + Info("Finished getting new pools") + + return pools, newMetadataBytes, nil +} + +// getAllPairsLength gets number of pairs from the factory contracts +func (u *PoolsListUpdater) getAllPairsLength(ctx context.Context) (int, error) { + var allPairsLength *big.Int + + getAllPairsLengthRequest := u.ethrpcClient.NewRequest().SetContext(ctx) + + getAllPairsLengthRequest.AddCall(ðrpc.Call{ + ABI: uniswapV2FactoryABI, + Target: u.config.FactoryAddress, + Method: factoryMethodAllPairsLength, + Params: nil, + }, []interface{}{&allPairsLength}) + + if _, err := getAllPairsLengthRequest.Call(); err != nil { + return 0, err + } + + return int(allPairsLength.Int64()), nil +} + +// getOffset gets index of the last pair that is fetched +func (u *PoolsListUpdater) getOffset(metadataBytes []byte) (int, error) { + if len(metadataBytes) == 0 { + return 0, nil + } + + var metadata PoolsListUpdaterMetadata + if err := json.Unmarshal(metadataBytes, &metadata); err != nil { + return 0, err + } + + return metadata.Offset, nil +} + +// listPairAddresses lists address of pairs from offset +func (u *PoolsListUpdater) listPairAddresses(ctx context.Context, offset int, batchSize int) ([]common.Address, error) { + listPairAddressesResult := make([]common.Address, batchSize) + + listPairAddressesRequest := u.ethrpcClient.NewRequest().SetContext(ctx) + + for i := 0; i < batchSize; i++ { + index := big.NewInt(int64(offset + i)) + + listPairAddressesRequest.AddCall(ðrpc.Call{ + ABI: uniswapV2FactoryABI, + Target: u.config.FactoryAddress, + Method: factoryMethodGetPair, + Params: []interface{}{index}, + }, []interface{}{&listPairAddressesResult[i]}) + } + + resp, err := listPairAddressesRequest.TryAggregate() + if err != nil { + return nil, err + } + + var pairAddresses []common.Address + for i, isSuccess := range resp.Result { + if !isSuccess { + continue + } + + pairAddresses = append(pairAddresses, listPairAddressesResult[i]) + } + + return pairAddresses, nil +} + +// initPools fetches token data and initializes pools +func (u *PoolsListUpdater) initPools(ctx context.Context, pairAddresses []common.Address) ([]entity.Pool, error) { + token0List, token1List, err := u.listPairTokens(ctx, pairAddresses) + if err != nil { + return nil, err + } + + pools := make([]entity.Pool, 0, len(pairAddresses)) + + for i, pairAddress := range pairAddresses { + token0 := &entity.PoolToken{ + Address: strings.ToLower(token0List[i].Hex()), + Swappable: true, + } + + token1 := &entity.PoolToken{ + Address: strings.ToLower(token1List[i].Hex()), + Swappable: true, + } + + var newPool = entity.Pool{ + Address: strings.ToLower(pairAddress.Hex()), + Exchange: u.config.DexID, + Type: DexType, + Timestamp: time.Now().Unix(), + Reserves: []string{"0", "0"}, + Tokens: []*entity.PoolToken{token0, token1}, + } + + pools = append(pools, newPool) + } + + return pools, nil +} + +// listPairTokens receives list of pair addresses and returns their token0 and token1 +func (u *PoolsListUpdater) listPairTokens(ctx context.Context, pairAddresses []common.Address) ([]common.Address, []common.Address, error) { + var ( + listToken0Result = make([]common.Address, len(pairAddresses)) + listToken1Result = make([]common.Address, len(pairAddresses)) + ) + + listTokensRequest := u.ethrpcClient.NewRequest().SetContext(ctx) + + for i, pairAddress := range pairAddresses { + listTokensRequest.AddCall(ðrpc.Call{ + ABI: uniswapV2PairABI, + Target: pairAddress.Hex(), + Method: pairMethodToken0, + Params: nil, + }, []interface{}{&listToken0Result[i]}) + + listTokensRequest.AddCall(ðrpc.Call{ + ABI: uniswapV2PairABI, + Target: pairAddress.Hex(), + Method: pairMethodToken1, + Params: nil, + }, []interface{}{&listToken1Result[i]}) + } + + if _, err := listTokensRequest.Aggregate(); err != nil { + return nil, nil, err + } + + return listToken0Result, listToken1Result, nil +} + +func (u *PoolsListUpdater) newMetadata(newOffset int) ([]byte, error) { + metadata := PoolsListUpdaterMetadata{ + Offset: newOffset, + } + + metadataBytes, err := json.Marshal(metadata) + if err != nil { + return nil, err + } + + return metadataBytes, nil +} + +// getBatchSize +// @params length number of pairs (factory tracked) +// @params limit number of pairs to be fetched in one run +// @params offset index of the last pair has been fetched +// @returns batchSize +func getBatchSize(length int, limit int, offset int) int { + if offset == length { + return 0 + } + + if offset+limit >= length { + return length - offset + } + + return limit +} diff --git a/pkg/liquidity-source/gravity/pool_simulator.go b/pkg/liquidity-source/gravity/pool_simulator.go new file mode 100644 index 000000000..3d8959e08 --- /dev/null +++ b/pkg/liquidity-source/gravity/pool_simulator.go @@ -0,0 +1,147 @@ +package gravity + +import ( + "errors" + "math/big" + + "github.com/holiman/uint256" + "github.com/samber/lo" + + "github.com/KyberNetwork/blockchain-toolkit/number" + + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + poolpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + utils "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/bignumber" +) + +var ( + ErrInvalidToken = errors.New("invalid token") + ErrInvalidReserve = errors.New("invalid reserve") + ErrInvalidAmountIn = errors.New("invalid amount in") + ErrInsufficientInputAmount = errors.New("INSUFFICIENT_INPUT_AMOUNT") + ErrInsufficientLiquidity = errors.New("INSUFFICIENT_LIQUIDITY") + ErrInvalidK = errors.New("K") +) + +var ( + getAmountOutRemainAfterFee = uint256.NewInt(997) + getAmountOutFeePrecision = uint256.NewInt(1000) + fee = uint256.NewInt(25) + feePrecision = uint256.NewInt(10000) + remainAfterGovFee = uint256.NewInt(9995) +) + +type ( + PoolSimulator struct { + poolpkg.Pool + + gas Gas + } + + Gas struct { + Swap int64 + } +) + +func NewPoolSimulator(entityPool entity.Pool) (*PoolSimulator, error) { + return &PoolSimulator{ + Pool: poolpkg.Pool{Info: poolpkg.PoolInfo{ + Address: entityPool.Address, + ReserveUsd: entityPool.ReserveUsd, + Exchange: entityPool.Exchange, + Type: entityPool.Type, + Tokens: lo.Map(entityPool.Tokens, func(item *entity.PoolToken, index int) string { return item.Address }), + Reserves: lo.Map(entityPool.Reserves, func(item string, index int) *big.Int { return utils.NewBig(item) }), + BlockNumber: entityPool.BlockNumber, + }}, + gas: defaultGas, + }, nil +} + +func (s *PoolSimulator) CalcAmountOut(param poolpkg.CalcAmountOutParams) (*poolpkg.CalcAmountOutResult, error) { + var ( + tokenAmountIn = param.TokenAmountIn + tokenOut = param.TokenOut + ) + indexIn, indexOut := s.GetTokenIndex(tokenAmountIn.Token), s.GetTokenIndex(tokenOut) + if indexIn < 0 || indexOut < 0 { + return nil, ErrInvalidToken + } + + amountIn, overflow := uint256.FromBig(tokenAmountIn.Amount) + if overflow { + return nil, ErrInvalidAmountIn + } + + if amountIn.Cmp(number.Zero) <= 0 { + return nil, ErrInsufficientInputAmount + } + + reserveIn, overflow := uint256.FromBig(s.Pool.Info.Reserves[indexIn]) + if overflow { + return nil, ErrInvalidReserve + } + + reserveOut, overflow := uint256.FromBig(s.Pool.Info.Reserves[indexOut]) + if overflow { + return nil, ErrInvalidReserve + } + + if reserveIn.Cmp(number.Zero) <= 0 || reserveOut.Cmp(number.Zero) <= 0 { + return nil, ErrInsufficientLiquidity + } + + amountOutBeforeGovFee := s.getAmountOut(amountIn, reserveIn, reserveOut) + amountOut := new(uint256.Int).Div(new(uint256.Int).Mul(amountOutBeforeGovFee, remainAfterGovFee), feePrecision) + if amountOut.Cmp(reserveOut) > 0 { + return nil, ErrInsufficientLiquidity + } + + balanceIn := new(uint256.Int).Add(reserveIn, amountIn) + balanceOut := new(uint256.Int).Sub(reserveOut, amountOut) + + balanceInAdjusted := new(uint256.Int).Sub( + new(uint256.Int).Mul(balanceIn, feePrecision), + new(uint256.Int).Mul(amountIn, fee), + ) + balanceOutAdjusted := new(uint256.Int).Mul(balanceOut, feePrecision) + + kBefore := new(uint256.Int).Mul(new(uint256.Int).Mul(reserveIn, reserveOut), new(uint256.Int).Mul(feePrecision, feePrecision)) + kAfter := new(uint256.Int).Mul(balanceInAdjusted, balanceOutAdjusted) + + if kAfter.Cmp(kBefore) < 0 { + return nil, ErrInvalidK + } + + return &poolpkg.CalcAmountOutResult{ + TokenAmountOut: &poolpkg.TokenAmount{Token: s.Pool.Info.Tokens[indexOut], Amount: amountOut.ToBig()}, + Fee: &poolpkg.TokenAmount{Token: s.Pool.Info.Tokens[indexIn], Amount: new(uint256.Int).Sub(amountOutBeforeGovFee, amountOut).ToBig()}, + Gas: s.gas.Swap, + }, nil +} + +func (s *PoolSimulator) UpdateBalance(params poolpkg.UpdateBalanceParams) { + indexIn := s.GetTokenIndex(params.TokenAmountIn.Token) + indexOut := s.GetTokenIndex(params.TokenAmountOut.Token) + if indexIn < 0 || indexOut < 0 { + return + } + s.Pool.Info.Reserves[indexIn] = new(big.Int).Add(s.Pool.Info.Reserves[indexIn], params.TokenAmountIn.Amount) + s.Pool.Info.Reserves[indexOut] = new(big.Int).Sub(new(big.Int).Sub(s.Pool.Info.Reserves[indexOut], params.TokenAmountOut.Amount), params.Fee.Amount) +} + +func (s *PoolSimulator) GetMetaInfo(_ string, _ string) interface{} { + return PoolMeta{ + Fee: 3, + FeePrecision: 10000, + BlockNumber: s.Pool.Info.BlockNumber, + } +} + +func (s *PoolSimulator) getAmountOut(amountIn, reserveIn, reserveOut *uint256.Int) *uint256.Int { + amountInWithFee := new(uint256.Int).Mul(amountIn, getAmountOutRemainAfterFee) + numerator := new(uint256.Int).Mul(amountInWithFee, reserveOut) + denominator := new(uint256.Int).Add(new(uint256.Int).Mul(reserveIn, getAmountOutFeePrecision), amountInWithFee) + + return new(uint256.Int).Div(numerator, denominator) +} diff --git a/pkg/liquidity-source/gravity/pool_simulator_test.go b/pkg/liquidity-source/gravity/pool_simulator_test.go new file mode 100644 index 000000000..64a5cdf11 --- /dev/null +++ b/pkg/liquidity-source/gravity/pool_simulator_test.go @@ -0,0 +1,227 @@ +package gravity + +import ( + "math/big" + "testing" + + "github.com/holiman/uint256" + "github.com/stretchr/testify/assert" + + "github.com/KyberNetwork/blockchain-toolkit/number" + + poolpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + utils "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/bignumber" +) + +// [0to1] https://polygonscan.com/tx/0xc3ae65a69af4130525d1fd6b0176bcb2bd47b5aa845c9420a929ef6dce8346bb +// [1to0] https://polygonscan.com/tx/0x0b8b28d9af5c291d15eaa5a71ccd29250482ca15560ba27b40e6c07affa70b52 +func TestPoolSimulator_CalcAmountOut(t *testing.T) { + testCases := []struct { + name string + poolSimulator PoolSimulator + tokenAmountIn poolpkg.TokenAmount + tokenOut string + expectedAmountOut *big.Int + expectedFee *big.Int + expectedError error + }{ + { + name: "[swap0to1] it should return correct amountOut and fee", + poolSimulator: PoolSimulator{ + Pool: poolpkg.Pool{ + Info: poolpkg.PoolInfo{ + Address: "0x0dfbf1a50bdcb570bd0ff7bb307313b553a02598", + Tokens: []string{"0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270", "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619a"}, + Reserves: []*big.Int{utils.NewBig("3676486287875125230347"), utils.NewBig("1595427043783762088")}, + }, + }, + }, + tokenAmountIn: poolpkg.TokenAmount{ + Amount: utils.NewBig("4541550000000000000"), + Token: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270", + }, + tokenOut: "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619a", + expectedAmountOut: utils.NewBig("1961514449578860"), + expectedFee: utils.NewBig("981247848714"), + expectedError: nil, + }, + { + name: "[swap1to0] it should return correct amountOut and fee", + poolSimulator: PoolSimulator{ + Pool: poolpkg.Pool{ + Info: poolpkg.PoolInfo{ + Address: "0x0dfbf1a50bdcb570bd0ff7bb307313b553a02598", + Tokens: []string{"0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270", "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619a"}, + Reserves: []*big.Int{utils.NewBig("3677564416437944883949"), utils.NewBig("1594968989213601445")}, + }, + }, + }, + tokenAmountIn: poolpkg.TokenAmount{ + Amount: utils.NewBig("667086035111400"), + Token: "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619a", + }, + tokenOut: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270", + expectedAmountOut: utils.NewBig("1532098871305218355"), + expectedFee: utils.NewBig("766432651978599"), + expectedError: nil, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + result, err := tc.poolSimulator.CalcAmountOut(poolpkg.CalcAmountOutParams{ + TokenAmountIn: tc.tokenAmountIn, + TokenOut: tc.tokenOut, + Limit: nil, + }) + + if tc.expectedError != nil { + assert.ErrorIs(t, tc.expectedError, err) + } else { + assert.Equal(t, tc.expectedAmountOut, result.TokenAmountOut.Amount) + assert.Equal(t, tc.expectedFee, result.Fee.Amount) + } + }) + } +} + +func TestPoolSimulator_UpdateBalance(t *testing.T) { + testCases := []struct { + name string + poolSimulator PoolSimulator + params poolpkg.UpdateBalanceParams + expectedReserves []*big.Int + }{ + { + name: "[swap0to1] it should return correct amountOut and fee", + poolSimulator: PoolSimulator{ + Pool: poolpkg.Pool{ + Info: poolpkg.PoolInfo{ + Address: "0x0dfbf1a50bdcb570bd0ff7bb307313b553a02598", + Tokens: []string{"0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270", "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619a"}, + Reserves: []*big.Int{utils.NewBig("3676486287875125230347"), utils.NewBig("1595427043783762088")}, + }, + }, + }, + params: poolpkg.UpdateBalanceParams{ + TokenAmountIn: poolpkg.TokenAmount{Token: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270", Amount: utils.NewBig("4541550000000000000")}, + TokenAmountOut: poolpkg.TokenAmount{Token: "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619a", Amount: utils.NewBig("1961514449578860")}, + Fee: poolpkg.TokenAmount{Token: "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619a", Amount: utils.NewBig("981247848714")}, + }, + expectedReserves: []*big.Int{utils.NewBig("3681027837875125230347"), utils.NewBig("1593464548086334514")}, + }, + { + name: "[swap1to0] it should return correct amountOut and fee", + poolSimulator: PoolSimulator{ + Pool: poolpkg.Pool{ + Info: poolpkg.PoolInfo{ + Address: "0x0dfbf1a50bdcb570bd0ff7bb307313b553a02598", + Tokens: []string{"0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270", "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619a"}, + Reserves: []*big.Int{utils.NewBig("3677564416437944883949"), utils.NewBig("1594968989213601445")}, + }, + }, + }, + params: poolpkg.UpdateBalanceParams{ + TokenAmountIn: poolpkg.TokenAmount{Token: "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619a", Amount: utils.NewBig("667086035111400")}, + TokenAmountOut: poolpkg.TokenAmount{Token: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270", Amount: utils.NewBig("1532098871305218355")}, + Fee: poolpkg.TokenAmount{Token: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270", Amount: utils.NewBig("766432651978599")}, + }, + expectedReserves: []*big.Int{utils.NewBig("3676031551133987686995"), utils.NewBig("1595636075248712845")}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + tc.poolSimulator.UpdateBalance(tc.params) + + assert.Equal(t, 0, tc.poolSimulator.Info.Reserves[0].Cmp(tc.expectedReserves[0])) + assert.Equal(t, 0, tc.poolSimulator.Info.Reserves[1].Cmp(tc.expectedReserves[1])) + }) + } +} + +func TestPoolSimulator_getAmountOut(t *testing.T) { + testCases := []struct { + name string + poolSimulator PoolSimulator + reserveIn *uint256.Int + reserveOut *uint256.Int + amountIn *uint256.Int + expectedAmountOut *uint256.Int + }{ + { + name: "it should return correct amountOut", + poolSimulator: PoolSimulator{}, + reserveIn: number.NewUint256("10089138480746"), + reserveOut: number.NewUint256("10066716097576"), + amountIn: number.NewUint256("125224746"), + expectedAmountOut: number.NewUint256("124570062"), + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + amountOut := tc.poolSimulator.getAmountOut(tc.amountIn, tc.reserveIn, tc.reserveOut) + + assert.Equal(t, 0, tc.expectedAmountOut.Cmp(amountOut)) + }) + } +} + +func BenchmarkPoolSimulatorCalcAmountOut(b *testing.B) { + testCases := []struct { + name string + poolSimulator PoolSimulator + tokenAmountIn poolpkg.TokenAmount + tokenOut string + expectedAmountOut *big.Int + expectedError error + }{ + { + name: "[swap0to1] it should return correct amountOut and fee", + poolSimulator: PoolSimulator{ + Pool: poolpkg.Pool{ + Info: poolpkg.PoolInfo{ + Address: "0x3041cbd36888becc7bbcbc0045e3b1f144466f5f", + Tokens: []string{"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0xdac17f958d2ee523a2206206994597c13d831ec7"}, + Reserves: []*big.Int{utils.NewBig("10089138480746"), utils.NewBig("10066716097576")}, + }, + }, + }, + tokenAmountIn: poolpkg.TokenAmount{ + Amount: utils.NewBig("125224746"), + Token: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", + }, + tokenOut: "0xdac17f958d2ee523a2206206994597c13d831ec7", + }, + { + name: "[swap1to0] it should return correct amountOut and fee", + poolSimulator: PoolSimulator{ + Pool: poolpkg.Pool{ + Info: poolpkg.PoolInfo{ + Address: "0x576cea6d4461fcb3a9d43e922c9b54c0f791599a", + Tokens: []string{"0x32a7c02e79c4ea1008dd6564b35f131428673c41", "0xdac17f958d2ee523a2206206994597c13d831ec7"}, + Reserves: []*big.Int{utils.NewBig("70361282326226590645832"), utils.NewBig("54150601005")}, + }, + }, + }, + tokenAmountIn: poolpkg.TokenAmount{ + Amount: utils.NewBig("124570062"), + Token: "0xdac17f958d2ee523a2206206994597c13d831ec7", + }, + tokenOut: "0x32a7c02e79c4ea1008dd6564b35f131428673c41", + }, + } + + for _, tc := range testCases { + b.Run(tc.name, func(b *testing.B) { + for i := 0; i < b.N; i++ { + _, _ = tc.poolSimulator.CalcAmountOut(poolpkg.CalcAmountOutParams{ + TokenAmountIn: tc.tokenAmountIn, + TokenOut: tc.tokenOut, + Limit: nil, + }) + } + }) + } +} diff --git a/pkg/liquidity-source/gravity/pool_tracker.go b/pkg/liquidity-source/gravity/pool_tracker.go new file mode 100644 index 000000000..e77c170b0 --- /dev/null +++ b/pkg/liquidity-source/gravity/pool_tracker.go @@ -0,0 +1,140 @@ +package gravity + +import ( + "context" + "math/big" + "time" + + "github.com/KyberNetwork/ethrpc" + "github.com/KyberNetwork/logger" + "github.com/ethereum/go-ethereum/core/types" + + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" +) + +type ( + ILogDecoder interface { + Decode(logs []types.Log) (ReserveData, *big.Int, error) + } + + PoolTracker struct { + ethrpcClient *ethrpc.Client + logDecoder ILogDecoder + } + + GetReservesResult struct { + Reserve0 *big.Int + Reserve1 *big.Int + BlockTimestampLast uint32 + } +) + +func NewPoolTracker( + ethrpcClient *ethrpc.Client, +) (*PoolTracker, error) { + return &PoolTracker{ + ethrpcClient: ethrpcClient, + logDecoder: NewLogDecoder(), + }, nil +} + +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + params pool.GetNewPoolStateParams, +) (entity.Pool, error) { + startTime := time.Now() + + logger.WithFields(logger.Fields{"pool_id": p.Address}).Info("Started getting new pool state") + + reserveData, blockNumber, err := d.getReserves(ctx, p.Address, params.Logs) + if err != nil { + return p, err + } + + if blockNumber != nil && p.BlockNumber > blockNumber.Uint64() { + logger. + WithFields( + logger.Fields{ + "pool_id": p.Address, + "pool_block_number": p.BlockNumber, + "data_block_number": blockNumber.Uint64(), + }, + ). + Info("skip update: data block number is less than current pool block number") + return p, nil + } + + logger. + WithFields( + logger.Fields{ + "pool_id": p.Address, + "old_reserve_0": p.Reserves[0], + "old_reserve_1": p.Reserves[1], + "new_reserve_0": reserveData.Reserve0.String(), + "new_reserve_1": reserveData.Reserve1.String(), + "old_block_number": p.BlockNumber, + "new_block_number": blockNumber, + "duration_ms": time.Since(startTime).Milliseconds(), + }, + ). + Info("Finished getting new pool state") + + return d.updatePool(p, reserveData, blockNumber), nil +} + +func (d *PoolTracker) getReserves(ctx context.Context, poolAddress string, logs []types.Log) (ReserveData, *big.Int, error) { + reserveData, blockNumber, err := d.getReservesFromLogs(logs) + if err != nil { + return d.getReservesFromRPCNode(ctx, poolAddress) + } + + if reserveData.IsZero() { + return d.getReservesFromRPCNode(ctx, poolAddress) + } + + return reserveData, blockNumber, nil +} + +func (d *PoolTracker) updatePool(pool entity.Pool, reserveData ReserveData, blockNumber *big.Int) entity.Pool { + pool.Reserves = entity.PoolReserves{ + reserveData.Reserve0.String(), + reserveData.Reserve1.String(), + } + pool.BlockNumber = blockNumber.Uint64() + pool.Timestamp = time.Now().Unix() + + return pool +} + +func (d *PoolTracker) getReservesFromRPCNode(ctx context.Context, poolAddress string) (ReserveData, *big.Int, error) { + var getReservesResult GetReservesResult + + getReservesRequest := d.ethrpcClient.NewRequest().SetContext(ctx) + + getReservesRequest.AddCall(ðrpc.Call{ + ABI: uniswapV2PairABI, + Target: poolAddress, + Method: pairMethodGetReserves, + Params: nil, + }, []interface{}{&getReservesResult}) + + resp, err := getReservesRequest.TryBlockAndAggregate() + if err != nil { + return ReserveData{}, nil, err + } + + return ReserveData{ + Reserve0: getReservesResult.Reserve0, + Reserve1: getReservesResult.Reserve1, + }, resp.BlockNumber, nil +} + +func (d *PoolTracker) getReservesFromLogs(logs []types.Log) (ReserveData, *big.Int, error) { + if len(logs) == 0 { + return ReserveData{}, nil, nil + } + + return d.logDecoder.Decode(logs) +} diff --git a/pkg/liquidity-source/gravity/types.go b/pkg/liquidity-source/gravity/types.go new file mode 100644 index 000000000..fe14ed421 --- /dev/null +++ b/pkg/liquidity-source/gravity/types.go @@ -0,0 +1,18 @@ +package gravity + +import "math/big" + +type ReserveData struct { + Reserve0 *big.Int + Reserve1 *big.Int +} + +func (d ReserveData) IsZero() bool { + return d.Reserve0 == nil && d.Reserve1 == nil +} + +type PoolMeta struct { + Fee uint64 `json:"fee"` + FeePrecision uint64 `json:"feePrecision"` + BlockNumber uint64 `json:"blockNumber"` +} diff --git a/pkg/liquidity-source/gravity/uniswap_pair.go b/pkg/liquidity-source/gravity/uniswap_pair.go new file mode 100644 index 000000000..beac72a07 --- /dev/null +++ b/pkg/liquidity-source/gravity/uniswap_pair.go @@ -0,0 +1,1842 @@ +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package gravity + +import ( + "errors" + "math/big" + "strings" + + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/event" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = errors.New + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = bind.Bind + _ = common.Big1 + _ = types.BloomLookup + _ = event.NewSubscription + _ = abi.ConvertType +) + +// UniswapMetaData contains all meta data concerning the Uniswap contract. +var UniswapMetaData = &bind.MetaData{ + ABI: "[{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount0\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount1\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"}],\"name\":\"Burn\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount0\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount1\",\"type\":\"uint256\"}],\"name\":\"Mint\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount0In\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount1In\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount0Out\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount1Out\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"}],\"name\":\"Swap\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint112\",\"name\":\"reserve0\",\"type\":\"uint112\"},{\"indexed\":false,\"internalType\":\"uint112\",\"name\":\"reserve1\",\"type\":\"uint112\"}],\"name\":\"Sync\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"constant\":true,\"inputs\":[],\"name\":\"DOMAIN_SEPARATOR\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"MINIMUM_LIQUIDITY\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"PERMIT_TYPEHASH\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"}],\"name\":\"burn\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amount0\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount1\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"factory\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getReserves\",\"outputs\":[{\"internalType\":\"uint112\",\"name\":\"_reserve0\",\"type\":\"uint112\"},{\"internalType\":\"uint112\",\"name\":\"_reserve1\",\"type\":\"uint112\"},{\"internalType\":\"uint32\",\"name\":\"_blockTimestampLast\",\"type\":\"uint32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"_token0\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_token1\",\"type\":\"address\"}],\"name\":\"initialize\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"kLast\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"}],\"name\":\"mint\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"liquidity\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"nonces\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"},{\"internalType\":\"uint8\",\"name\":\"v\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"r\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"s\",\"type\":\"bytes32\"}],\"name\":\"permit\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"price0CumulativeLast\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"price1CumulativeLast\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"}],\"name\":\"skim\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amount0Out\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount1Out\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"swap\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"sync\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"token0\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"token1\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", +} + +// UniswapABI is the input ABI used to generate the binding from. +// Deprecated: Use UniswapMetaData.ABI instead. +var UniswapABI = UniswapMetaData.ABI + +// Uniswap is an auto generated Go binding around an Ethereum contract. +type Uniswap struct { + UniswapCaller // Read-only binding to the contract + UniswapTransactor // Write-only binding to the contract + UniswapFilterer // Log filterer for contract events +} + +// UniswapCaller is an auto generated read-only Go binding around an Ethereum contract. +type UniswapCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// UniswapTransactor is an auto generated write-only Go binding around an Ethereum contract. +type UniswapTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// UniswapFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type UniswapFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// UniswapSession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type UniswapSession struct { + Contract *Uniswap // Generic contract binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// UniswapCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type UniswapCallerSession struct { + Contract *UniswapCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// UniswapTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type UniswapTransactorSession struct { + Contract *UniswapTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// UniswapRaw is an auto generated low-level Go binding around an Ethereum contract. +type UniswapRaw struct { + Contract *Uniswap // Generic contract binding to access the raw methods on +} + +// UniswapCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type UniswapCallerRaw struct { + Contract *UniswapCaller // Generic read-only contract binding to access the raw methods on +} + +// UniswapTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type UniswapTransactorRaw struct { + Contract *UniswapTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewUniswap creates a new instance of Uniswap, bound to a specific deployed contract. +func NewUniswap(address common.Address, backend bind.ContractBackend) (*Uniswap, error) { + contract, err := bindUniswap(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &Uniswap{UniswapCaller: UniswapCaller{contract: contract}, UniswapTransactor: UniswapTransactor{contract: contract}, UniswapFilterer: UniswapFilterer{contract: contract}}, nil +} + +// NewUniswapCaller creates a new read-only instance of Uniswap, bound to a specific deployed contract. +func NewUniswapCaller(address common.Address, caller bind.ContractCaller) (*UniswapCaller, error) { + contract, err := bindUniswap(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &UniswapCaller{contract: contract}, nil +} + +// NewUniswapTransactor creates a new write-only instance of Uniswap, bound to a specific deployed contract. +func NewUniswapTransactor(address common.Address, transactor bind.ContractTransactor) (*UniswapTransactor, error) { + contract, err := bindUniswap(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &UniswapTransactor{contract: contract}, nil +} + +// NewUniswapFilterer creates a new log filterer instance of Uniswap, bound to a specific deployed contract. +func NewUniswapFilterer(address common.Address, filterer bind.ContractFilterer) (*UniswapFilterer, error) { + contract, err := bindUniswap(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &UniswapFilterer{contract: contract}, nil +} + +// bindUniswap binds a generic wrapper to an already deployed contract. +func bindUniswap(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := UniswapMetaData.GetAbi() + if err != nil { + return nil, err + } + return bind.NewBoundContract(address, *parsed, caller, transactor, filterer), nil +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Uniswap *UniswapRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Uniswap.Contract.UniswapCaller.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Uniswap *UniswapRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Uniswap.Contract.UniswapTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Uniswap *UniswapRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Uniswap.Contract.UniswapTransactor.contract.Transact(opts, method, params...) +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Uniswap *UniswapCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Uniswap.Contract.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Uniswap *UniswapTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Uniswap.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Uniswap *UniswapTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Uniswap.Contract.contract.Transact(opts, method, params...) +} + +// DOMAINSEPARATOR is a free data retrieval call binding the contract method 0x3644e515. +// +// Solidity: function DOMAIN_SEPARATOR() view returns(bytes32) +func (_Uniswap *UniswapCaller) DOMAINSEPARATOR(opts *bind.CallOpts) ([32]byte, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "DOMAIN_SEPARATOR") + + if err != nil { + return *new([32]byte), err + } + + out0 := *abi.ConvertType(out[0], new([32]byte)).(*[32]byte) + + return out0, err + +} + +// DOMAINSEPARATOR is a free data retrieval call binding the contract method 0x3644e515. +// +// Solidity: function DOMAIN_SEPARATOR() view returns(bytes32) +func (_Uniswap *UniswapSession) DOMAINSEPARATOR() ([32]byte, error) { + return _Uniswap.Contract.DOMAINSEPARATOR(&_Uniswap.CallOpts) +} + +// DOMAINSEPARATOR is a free data retrieval call binding the contract method 0x3644e515. +// +// Solidity: function DOMAIN_SEPARATOR() view returns(bytes32) +func (_Uniswap *UniswapCallerSession) DOMAINSEPARATOR() ([32]byte, error) { + return _Uniswap.Contract.DOMAINSEPARATOR(&_Uniswap.CallOpts) +} + +// MINIMUMLIQUIDITY is a free data retrieval call binding the contract method 0xba9a7a56. +// +// Solidity: function MINIMUM_LIQUIDITY() view returns(uint256) +func (_Uniswap *UniswapCaller) MINIMUMLIQUIDITY(opts *bind.CallOpts) (*big.Int, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "MINIMUM_LIQUIDITY") + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// MINIMUMLIQUIDITY is a free data retrieval call binding the contract method 0xba9a7a56. +// +// Solidity: function MINIMUM_LIQUIDITY() view returns(uint256) +func (_Uniswap *UniswapSession) MINIMUMLIQUIDITY() (*big.Int, error) { + return _Uniswap.Contract.MINIMUMLIQUIDITY(&_Uniswap.CallOpts) +} + +// MINIMUMLIQUIDITY is a free data retrieval call binding the contract method 0xba9a7a56. +// +// Solidity: function MINIMUM_LIQUIDITY() view returns(uint256) +func (_Uniswap *UniswapCallerSession) MINIMUMLIQUIDITY() (*big.Int, error) { + return _Uniswap.Contract.MINIMUMLIQUIDITY(&_Uniswap.CallOpts) +} + +// PERMITTYPEHASH is a free data retrieval call binding the contract method 0x30adf81f. +// +// Solidity: function PERMIT_TYPEHASH() view returns(bytes32) +func (_Uniswap *UniswapCaller) PERMITTYPEHASH(opts *bind.CallOpts) ([32]byte, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "PERMIT_TYPEHASH") + + if err != nil { + return *new([32]byte), err + } + + out0 := *abi.ConvertType(out[0], new([32]byte)).(*[32]byte) + + return out0, err + +} + +// PERMITTYPEHASH is a free data retrieval call binding the contract method 0x30adf81f. +// +// Solidity: function PERMIT_TYPEHASH() view returns(bytes32) +func (_Uniswap *UniswapSession) PERMITTYPEHASH() ([32]byte, error) { + return _Uniswap.Contract.PERMITTYPEHASH(&_Uniswap.CallOpts) +} + +// PERMITTYPEHASH is a free data retrieval call binding the contract method 0x30adf81f. +// +// Solidity: function PERMIT_TYPEHASH() view returns(bytes32) +func (_Uniswap *UniswapCallerSession) PERMITTYPEHASH() ([32]byte, error) { + return _Uniswap.Contract.PERMITTYPEHASH(&_Uniswap.CallOpts) +} + +// Allowance is a free data retrieval call binding the contract method 0xdd62ed3e. +// +// Solidity: function allowance(address , address ) view returns(uint256) +func (_Uniswap *UniswapCaller) Allowance(opts *bind.CallOpts, arg0 common.Address, arg1 common.Address) (*big.Int, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "allowance", arg0, arg1) + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// Allowance is a free data retrieval call binding the contract method 0xdd62ed3e. +// +// Solidity: function allowance(address , address ) view returns(uint256) +func (_Uniswap *UniswapSession) Allowance(arg0 common.Address, arg1 common.Address) (*big.Int, error) { + return _Uniswap.Contract.Allowance(&_Uniswap.CallOpts, arg0, arg1) +} + +// Allowance is a free data retrieval call binding the contract method 0xdd62ed3e. +// +// Solidity: function allowance(address , address ) view returns(uint256) +func (_Uniswap *UniswapCallerSession) Allowance(arg0 common.Address, arg1 common.Address) (*big.Int, error) { + return _Uniswap.Contract.Allowance(&_Uniswap.CallOpts, arg0, arg1) +} + +// BalanceOf is a free data retrieval call binding the contract method 0x70a08231. +// +// Solidity: function balanceOf(address ) view returns(uint256) +func (_Uniswap *UniswapCaller) BalanceOf(opts *bind.CallOpts, arg0 common.Address) (*big.Int, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "balanceOf", arg0) + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// BalanceOf is a free data retrieval call binding the contract method 0x70a08231. +// +// Solidity: function balanceOf(address ) view returns(uint256) +func (_Uniswap *UniswapSession) BalanceOf(arg0 common.Address) (*big.Int, error) { + return _Uniswap.Contract.BalanceOf(&_Uniswap.CallOpts, arg0) +} + +// BalanceOf is a free data retrieval call binding the contract method 0x70a08231. +// +// Solidity: function balanceOf(address ) view returns(uint256) +func (_Uniswap *UniswapCallerSession) BalanceOf(arg0 common.Address) (*big.Int, error) { + return _Uniswap.Contract.BalanceOf(&_Uniswap.CallOpts, arg0) +} + +// Decimals is a free data retrieval call binding the contract method 0x313ce567. +// +// Solidity: function decimals() view returns(uint8) +func (_Uniswap *UniswapCaller) Decimals(opts *bind.CallOpts) (uint8, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "decimals") + + if err != nil { + return *new(uint8), err + } + + out0 := *abi.ConvertType(out[0], new(uint8)).(*uint8) + + return out0, err + +} + +// Decimals is a free data retrieval call binding the contract method 0x313ce567. +// +// Solidity: function decimals() view returns(uint8) +func (_Uniswap *UniswapSession) Decimals() (uint8, error) { + return _Uniswap.Contract.Decimals(&_Uniswap.CallOpts) +} + +// Decimals is a free data retrieval call binding the contract method 0x313ce567. +// +// Solidity: function decimals() view returns(uint8) +func (_Uniswap *UniswapCallerSession) Decimals() (uint8, error) { + return _Uniswap.Contract.Decimals(&_Uniswap.CallOpts) +} + +// Factory is a free data retrieval call binding the contract method 0xc45a0155. +// +// Solidity: function factory() view returns(address) +func (_Uniswap *UniswapCaller) Factory(opts *bind.CallOpts) (common.Address, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "factory") + + if err != nil { + return *new(common.Address), err + } + + out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address) + + return out0, err + +} + +// Factory is a free data retrieval call binding the contract method 0xc45a0155. +// +// Solidity: function factory() view returns(address) +func (_Uniswap *UniswapSession) Factory() (common.Address, error) { + return _Uniswap.Contract.Factory(&_Uniswap.CallOpts) +} + +// Factory is a free data retrieval call binding the contract method 0xc45a0155. +// +// Solidity: function factory() view returns(address) +func (_Uniswap *UniswapCallerSession) Factory() (common.Address, error) { + return _Uniswap.Contract.Factory(&_Uniswap.CallOpts) +} + +// GetReserves is a free data retrieval call binding the contract method 0x0902f1ac. +// +// Solidity: function getReserves() view returns(uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) +func (_Uniswap *UniswapCaller) GetReserves(opts *bind.CallOpts) (struct { + Reserve0 *big.Int + Reserve1 *big.Int + BlockTimestampLast uint32 +}, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "getReserves") + + outstruct := new(struct { + Reserve0 *big.Int + Reserve1 *big.Int + BlockTimestampLast uint32 + }) + if err != nil { + return *outstruct, err + } + + outstruct.Reserve0 = *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + outstruct.Reserve1 = *abi.ConvertType(out[1], new(*big.Int)).(**big.Int) + outstruct.BlockTimestampLast = *abi.ConvertType(out[2], new(uint32)).(*uint32) + + return *outstruct, err + +} + +// GetReserves is a free data retrieval call binding the contract method 0x0902f1ac. +// +// Solidity: function getReserves() view returns(uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) +func (_Uniswap *UniswapSession) GetReserves() (struct { + Reserve0 *big.Int + Reserve1 *big.Int + BlockTimestampLast uint32 +}, error) { + return _Uniswap.Contract.GetReserves(&_Uniswap.CallOpts) +} + +// GetReserves is a free data retrieval call binding the contract method 0x0902f1ac. +// +// Solidity: function getReserves() view returns(uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) +func (_Uniswap *UniswapCallerSession) GetReserves() (struct { + Reserve0 *big.Int + Reserve1 *big.Int + BlockTimestampLast uint32 +}, error) { + return _Uniswap.Contract.GetReserves(&_Uniswap.CallOpts) +} + +// KLast is a free data retrieval call binding the contract method 0x7464fc3d. +// +// Solidity: function kLast() view returns(uint256) +func (_Uniswap *UniswapCaller) KLast(opts *bind.CallOpts) (*big.Int, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "kLast") + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// KLast is a free data retrieval call binding the contract method 0x7464fc3d. +// +// Solidity: function kLast() view returns(uint256) +func (_Uniswap *UniswapSession) KLast() (*big.Int, error) { + return _Uniswap.Contract.KLast(&_Uniswap.CallOpts) +} + +// KLast is a free data retrieval call binding the contract method 0x7464fc3d. +// +// Solidity: function kLast() view returns(uint256) +func (_Uniswap *UniswapCallerSession) KLast() (*big.Int, error) { + return _Uniswap.Contract.KLast(&_Uniswap.CallOpts) +} + +// Name is a free data retrieval call binding the contract method 0x06fdde03. +// +// Solidity: function name() view returns(string) +func (_Uniswap *UniswapCaller) Name(opts *bind.CallOpts) (string, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "name") + + if err != nil { + return *new(string), err + } + + out0 := *abi.ConvertType(out[0], new(string)).(*string) + + return out0, err + +} + +// Name is a free data retrieval call binding the contract method 0x06fdde03. +// +// Solidity: function name() view returns(string) +func (_Uniswap *UniswapSession) Name() (string, error) { + return _Uniswap.Contract.Name(&_Uniswap.CallOpts) +} + +// Name is a free data retrieval call binding the contract method 0x06fdde03. +// +// Solidity: function name() view returns(string) +func (_Uniswap *UniswapCallerSession) Name() (string, error) { + return _Uniswap.Contract.Name(&_Uniswap.CallOpts) +} + +// Nonces is a free data retrieval call binding the contract method 0x7ecebe00. +// +// Solidity: function nonces(address ) view returns(uint256) +func (_Uniswap *UniswapCaller) Nonces(opts *bind.CallOpts, arg0 common.Address) (*big.Int, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "nonces", arg0) + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// Nonces is a free data retrieval call binding the contract method 0x7ecebe00. +// +// Solidity: function nonces(address ) view returns(uint256) +func (_Uniswap *UniswapSession) Nonces(arg0 common.Address) (*big.Int, error) { + return _Uniswap.Contract.Nonces(&_Uniswap.CallOpts, arg0) +} + +// Nonces is a free data retrieval call binding the contract method 0x7ecebe00. +// +// Solidity: function nonces(address ) view returns(uint256) +func (_Uniswap *UniswapCallerSession) Nonces(arg0 common.Address) (*big.Int, error) { + return _Uniswap.Contract.Nonces(&_Uniswap.CallOpts, arg0) +} + +// Price0CumulativeLast is a free data retrieval call binding the contract method 0x5909c0d5. +// +// Solidity: function price0CumulativeLast() view returns(uint256) +func (_Uniswap *UniswapCaller) Price0CumulativeLast(opts *bind.CallOpts) (*big.Int, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "price0CumulativeLast") + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// Price0CumulativeLast is a free data retrieval call binding the contract method 0x5909c0d5. +// +// Solidity: function price0CumulativeLast() view returns(uint256) +func (_Uniswap *UniswapSession) Price0CumulativeLast() (*big.Int, error) { + return _Uniswap.Contract.Price0CumulativeLast(&_Uniswap.CallOpts) +} + +// Price0CumulativeLast is a free data retrieval call binding the contract method 0x5909c0d5. +// +// Solidity: function price0CumulativeLast() view returns(uint256) +func (_Uniswap *UniswapCallerSession) Price0CumulativeLast() (*big.Int, error) { + return _Uniswap.Contract.Price0CumulativeLast(&_Uniswap.CallOpts) +} + +// Price1CumulativeLast is a free data retrieval call binding the contract method 0x5a3d5493. +// +// Solidity: function price1CumulativeLast() view returns(uint256) +func (_Uniswap *UniswapCaller) Price1CumulativeLast(opts *bind.CallOpts) (*big.Int, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "price1CumulativeLast") + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// Price1CumulativeLast is a free data retrieval call binding the contract method 0x5a3d5493. +// +// Solidity: function price1CumulativeLast() view returns(uint256) +func (_Uniswap *UniswapSession) Price1CumulativeLast() (*big.Int, error) { + return _Uniswap.Contract.Price1CumulativeLast(&_Uniswap.CallOpts) +} + +// Price1CumulativeLast is a free data retrieval call binding the contract method 0x5a3d5493. +// +// Solidity: function price1CumulativeLast() view returns(uint256) +func (_Uniswap *UniswapCallerSession) Price1CumulativeLast() (*big.Int, error) { + return _Uniswap.Contract.Price1CumulativeLast(&_Uniswap.CallOpts) +} + +// Symbol is a free data retrieval call binding the contract method 0x95d89b41. +// +// Solidity: function symbol() view returns(string) +func (_Uniswap *UniswapCaller) Symbol(opts *bind.CallOpts) (string, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "symbol") + + if err != nil { + return *new(string), err + } + + out0 := *abi.ConvertType(out[0], new(string)).(*string) + + return out0, err + +} + +// Symbol is a free data retrieval call binding the contract method 0x95d89b41. +// +// Solidity: function symbol() view returns(string) +func (_Uniswap *UniswapSession) Symbol() (string, error) { + return _Uniswap.Contract.Symbol(&_Uniswap.CallOpts) +} + +// Symbol is a free data retrieval call binding the contract method 0x95d89b41. +// +// Solidity: function symbol() view returns(string) +func (_Uniswap *UniswapCallerSession) Symbol() (string, error) { + return _Uniswap.Contract.Symbol(&_Uniswap.CallOpts) +} + +// Token0 is a free data retrieval call binding the contract method 0x0dfe1681. +// +// Solidity: function token0() view returns(address) +func (_Uniswap *UniswapCaller) Token0(opts *bind.CallOpts) (common.Address, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "token0") + + if err != nil { + return *new(common.Address), err + } + + out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address) + + return out0, err + +} + +// Token0 is a free data retrieval call binding the contract method 0x0dfe1681. +// +// Solidity: function token0() view returns(address) +func (_Uniswap *UniswapSession) Token0() (common.Address, error) { + return _Uniswap.Contract.Token0(&_Uniswap.CallOpts) +} + +// Token0 is a free data retrieval call binding the contract method 0x0dfe1681. +// +// Solidity: function token0() view returns(address) +func (_Uniswap *UniswapCallerSession) Token0() (common.Address, error) { + return _Uniswap.Contract.Token0(&_Uniswap.CallOpts) +} + +// Token1 is a free data retrieval call binding the contract method 0xd21220a7. +// +// Solidity: function token1() view returns(address) +func (_Uniswap *UniswapCaller) Token1(opts *bind.CallOpts) (common.Address, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "token1") + + if err != nil { + return *new(common.Address), err + } + + out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address) + + return out0, err + +} + +// Token1 is a free data retrieval call binding the contract method 0xd21220a7. +// +// Solidity: function token1() view returns(address) +func (_Uniswap *UniswapSession) Token1() (common.Address, error) { + return _Uniswap.Contract.Token1(&_Uniswap.CallOpts) +} + +// Token1 is a free data retrieval call binding the contract method 0xd21220a7. +// +// Solidity: function token1() view returns(address) +func (_Uniswap *UniswapCallerSession) Token1() (common.Address, error) { + return _Uniswap.Contract.Token1(&_Uniswap.CallOpts) +} + +// TotalSupply is a free data retrieval call binding the contract method 0x18160ddd. +// +// Solidity: function totalSupply() view returns(uint256) +func (_Uniswap *UniswapCaller) TotalSupply(opts *bind.CallOpts) (*big.Int, error) { + var out []interface{} + err := _Uniswap.contract.Call(opts, &out, "totalSupply") + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// TotalSupply is a free data retrieval call binding the contract method 0x18160ddd. +// +// Solidity: function totalSupply() view returns(uint256) +func (_Uniswap *UniswapSession) TotalSupply() (*big.Int, error) { + return _Uniswap.Contract.TotalSupply(&_Uniswap.CallOpts) +} + +// TotalSupply is a free data retrieval call binding the contract method 0x18160ddd. +// +// Solidity: function totalSupply() view returns(uint256) +func (_Uniswap *UniswapCallerSession) TotalSupply() (*big.Int, error) { + return _Uniswap.Contract.TotalSupply(&_Uniswap.CallOpts) +} + +// Approve is a paid mutator transaction binding the contract method 0x095ea7b3. +// +// Solidity: function approve(address spender, uint256 value) returns(bool) +func (_Uniswap *UniswapTransactor) Approve(opts *bind.TransactOpts, spender common.Address, value *big.Int) (*types.Transaction, error) { + return _Uniswap.contract.Transact(opts, "approve", spender, value) +} + +// Approve is a paid mutator transaction binding the contract method 0x095ea7b3. +// +// Solidity: function approve(address spender, uint256 value) returns(bool) +func (_Uniswap *UniswapSession) Approve(spender common.Address, value *big.Int) (*types.Transaction, error) { + return _Uniswap.Contract.Approve(&_Uniswap.TransactOpts, spender, value) +} + +// Approve is a paid mutator transaction binding the contract method 0x095ea7b3. +// +// Solidity: function approve(address spender, uint256 value) returns(bool) +func (_Uniswap *UniswapTransactorSession) Approve(spender common.Address, value *big.Int) (*types.Transaction, error) { + return _Uniswap.Contract.Approve(&_Uniswap.TransactOpts, spender, value) +} + +// Burn is a paid mutator transaction binding the contract method 0x89afcb44. +// +// Solidity: function burn(address to) returns(uint256 amount0, uint256 amount1) +func (_Uniswap *UniswapTransactor) Burn(opts *bind.TransactOpts, to common.Address) (*types.Transaction, error) { + return _Uniswap.contract.Transact(opts, "burn", to) +} + +// Burn is a paid mutator transaction binding the contract method 0x89afcb44. +// +// Solidity: function burn(address to) returns(uint256 amount0, uint256 amount1) +func (_Uniswap *UniswapSession) Burn(to common.Address) (*types.Transaction, error) { + return _Uniswap.Contract.Burn(&_Uniswap.TransactOpts, to) +} + +// Burn is a paid mutator transaction binding the contract method 0x89afcb44. +// +// Solidity: function burn(address to) returns(uint256 amount0, uint256 amount1) +func (_Uniswap *UniswapTransactorSession) Burn(to common.Address) (*types.Transaction, error) { + return _Uniswap.Contract.Burn(&_Uniswap.TransactOpts, to) +} + +// Initialize is a paid mutator transaction binding the contract method 0x485cc955. +// +// Solidity: function initialize(address _token0, address _token1) returns() +func (_Uniswap *UniswapTransactor) Initialize(opts *bind.TransactOpts, _token0 common.Address, _token1 common.Address) (*types.Transaction, error) { + return _Uniswap.contract.Transact(opts, "initialize", _token0, _token1) +} + +// Initialize is a paid mutator transaction binding the contract method 0x485cc955. +// +// Solidity: function initialize(address _token0, address _token1) returns() +func (_Uniswap *UniswapSession) Initialize(_token0 common.Address, _token1 common.Address) (*types.Transaction, error) { + return _Uniswap.Contract.Initialize(&_Uniswap.TransactOpts, _token0, _token1) +} + +// Initialize is a paid mutator transaction binding the contract method 0x485cc955. +// +// Solidity: function initialize(address _token0, address _token1) returns() +func (_Uniswap *UniswapTransactorSession) Initialize(_token0 common.Address, _token1 common.Address) (*types.Transaction, error) { + return _Uniswap.Contract.Initialize(&_Uniswap.TransactOpts, _token0, _token1) +} + +// Mint is a paid mutator transaction binding the contract method 0x6a627842. +// +// Solidity: function mint(address to) returns(uint256 liquidity) +func (_Uniswap *UniswapTransactor) Mint(opts *bind.TransactOpts, to common.Address) (*types.Transaction, error) { + return _Uniswap.contract.Transact(opts, "mint", to) +} + +// Mint is a paid mutator transaction binding the contract method 0x6a627842. +// +// Solidity: function mint(address to) returns(uint256 liquidity) +func (_Uniswap *UniswapSession) Mint(to common.Address) (*types.Transaction, error) { + return _Uniswap.Contract.Mint(&_Uniswap.TransactOpts, to) +} + +// Mint is a paid mutator transaction binding the contract method 0x6a627842. +// +// Solidity: function mint(address to) returns(uint256 liquidity) +func (_Uniswap *UniswapTransactorSession) Mint(to common.Address) (*types.Transaction, error) { + return _Uniswap.Contract.Mint(&_Uniswap.TransactOpts, to) +} + +// Permit is a paid mutator transaction binding the contract method 0xd505accf. +// +// Solidity: function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) returns() +func (_Uniswap *UniswapTransactor) Permit(opts *bind.TransactOpts, owner common.Address, spender common.Address, value *big.Int, deadline *big.Int, v uint8, r [32]byte, s [32]byte) (*types.Transaction, error) { + return _Uniswap.contract.Transact(opts, "permit", owner, spender, value, deadline, v, r, s) +} + +// Permit is a paid mutator transaction binding the contract method 0xd505accf. +// +// Solidity: function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) returns() +func (_Uniswap *UniswapSession) Permit(owner common.Address, spender common.Address, value *big.Int, deadline *big.Int, v uint8, r [32]byte, s [32]byte) (*types.Transaction, error) { + return _Uniswap.Contract.Permit(&_Uniswap.TransactOpts, owner, spender, value, deadline, v, r, s) +} + +// Permit is a paid mutator transaction binding the contract method 0xd505accf. +// +// Solidity: function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) returns() +func (_Uniswap *UniswapTransactorSession) Permit(owner common.Address, spender common.Address, value *big.Int, deadline *big.Int, v uint8, r [32]byte, s [32]byte) (*types.Transaction, error) { + return _Uniswap.Contract.Permit(&_Uniswap.TransactOpts, owner, spender, value, deadline, v, r, s) +} + +// Skim is a paid mutator transaction binding the contract method 0xbc25cf77. +// +// Solidity: function skim(address to) returns() +func (_Uniswap *UniswapTransactor) Skim(opts *bind.TransactOpts, to common.Address) (*types.Transaction, error) { + return _Uniswap.contract.Transact(opts, "skim", to) +} + +// Skim is a paid mutator transaction binding the contract method 0xbc25cf77. +// +// Solidity: function skim(address to) returns() +func (_Uniswap *UniswapSession) Skim(to common.Address) (*types.Transaction, error) { + return _Uniswap.Contract.Skim(&_Uniswap.TransactOpts, to) +} + +// Skim is a paid mutator transaction binding the contract method 0xbc25cf77. +// +// Solidity: function skim(address to) returns() +func (_Uniswap *UniswapTransactorSession) Skim(to common.Address) (*types.Transaction, error) { + return _Uniswap.Contract.Skim(&_Uniswap.TransactOpts, to) +} + +// Swap is a paid mutator transaction binding the contract method 0x022c0d9f. +// +// Solidity: function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes data) returns() +func (_Uniswap *UniswapTransactor) Swap(opts *bind.TransactOpts, amount0Out *big.Int, amount1Out *big.Int, to common.Address, data []byte) (*types.Transaction, error) { + return _Uniswap.contract.Transact(opts, "swap", amount0Out, amount1Out, to, data) +} + +// Swap is a paid mutator transaction binding the contract method 0x022c0d9f. +// +// Solidity: function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes data) returns() +func (_Uniswap *UniswapSession) Swap(amount0Out *big.Int, amount1Out *big.Int, to common.Address, data []byte) (*types.Transaction, error) { + return _Uniswap.Contract.Swap(&_Uniswap.TransactOpts, amount0Out, amount1Out, to, data) +} + +// Swap is a paid mutator transaction binding the contract method 0x022c0d9f. +// +// Solidity: function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes data) returns() +func (_Uniswap *UniswapTransactorSession) Swap(amount0Out *big.Int, amount1Out *big.Int, to common.Address, data []byte) (*types.Transaction, error) { + return _Uniswap.Contract.Swap(&_Uniswap.TransactOpts, amount0Out, amount1Out, to, data) +} + +// Sync is a paid mutator transaction binding the contract method 0xfff6cae9. +// +// Solidity: function sync() returns() +func (_Uniswap *UniswapTransactor) Sync(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Uniswap.contract.Transact(opts, "sync") +} + +// Sync is a paid mutator transaction binding the contract method 0xfff6cae9. +// +// Solidity: function sync() returns() +func (_Uniswap *UniswapSession) Sync() (*types.Transaction, error) { + return _Uniswap.Contract.Sync(&_Uniswap.TransactOpts) +} + +// Sync is a paid mutator transaction binding the contract method 0xfff6cae9. +// +// Solidity: function sync() returns() +func (_Uniswap *UniswapTransactorSession) Sync() (*types.Transaction, error) { + return _Uniswap.Contract.Sync(&_Uniswap.TransactOpts) +} + +// Transfer is a paid mutator transaction binding the contract method 0xa9059cbb. +// +// Solidity: function transfer(address to, uint256 value) returns(bool) +func (_Uniswap *UniswapTransactor) Transfer(opts *bind.TransactOpts, to common.Address, value *big.Int) (*types.Transaction, error) { + return _Uniswap.contract.Transact(opts, "transfer", to, value) +} + +// Transfer is a paid mutator transaction binding the contract method 0xa9059cbb. +// +// Solidity: function transfer(address to, uint256 value) returns(bool) +func (_Uniswap *UniswapSession) Transfer(to common.Address, value *big.Int) (*types.Transaction, error) { + return _Uniswap.Contract.Transfer(&_Uniswap.TransactOpts, to, value) +} + +// Transfer is a paid mutator transaction binding the contract method 0xa9059cbb. +// +// Solidity: function transfer(address to, uint256 value) returns(bool) +func (_Uniswap *UniswapTransactorSession) Transfer(to common.Address, value *big.Int) (*types.Transaction, error) { + return _Uniswap.Contract.Transfer(&_Uniswap.TransactOpts, to, value) +} + +// TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd. +// +// Solidity: function transferFrom(address from, address to, uint256 value) returns(bool) +func (_Uniswap *UniswapTransactor) TransferFrom(opts *bind.TransactOpts, from common.Address, to common.Address, value *big.Int) (*types.Transaction, error) { + return _Uniswap.contract.Transact(opts, "transferFrom", from, to, value) +} + +// TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd. +// +// Solidity: function transferFrom(address from, address to, uint256 value) returns(bool) +func (_Uniswap *UniswapSession) TransferFrom(from common.Address, to common.Address, value *big.Int) (*types.Transaction, error) { + return _Uniswap.Contract.TransferFrom(&_Uniswap.TransactOpts, from, to, value) +} + +// TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd. +// +// Solidity: function transferFrom(address from, address to, uint256 value) returns(bool) +func (_Uniswap *UniswapTransactorSession) TransferFrom(from common.Address, to common.Address, value *big.Int) (*types.Transaction, error) { + return _Uniswap.Contract.TransferFrom(&_Uniswap.TransactOpts, from, to, value) +} + +// UniswapApprovalIterator is returned from FilterApproval and is used to iterate over the raw logs and unpacked data for Approval events raised by the Uniswap contract. +type UniswapApprovalIterator struct { + Event *UniswapApproval // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *UniswapApprovalIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(UniswapApproval) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(UniswapApproval) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *UniswapApprovalIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *UniswapApprovalIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// UniswapApproval represents a Approval event raised by the Uniswap contract. +type UniswapApproval struct { + Owner common.Address + Spender common.Address + Value *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterApproval is a free log retrieval operation binding the contract event 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925. +// +// Solidity: event Approval(address indexed owner, address indexed spender, uint256 value) +func (_Uniswap *UniswapFilterer) FilterApproval(opts *bind.FilterOpts, owner []common.Address, spender []common.Address) (*UniswapApprovalIterator, error) { + + var ownerRule []interface{} + for _, ownerItem := range owner { + ownerRule = append(ownerRule, ownerItem) + } + var spenderRule []interface{} + for _, spenderItem := range spender { + spenderRule = append(spenderRule, spenderItem) + } + + logs, sub, err := _Uniswap.contract.FilterLogs(opts, "Approval", ownerRule, spenderRule) + if err != nil { + return nil, err + } + return &UniswapApprovalIterator{contract: _Uniswap.contract, event: "Approval", logs: logs, sub: sub}, nil +} + +// WatchApproval is a free log subscription operation binding the contract event 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925. +// +// Solidity: event Approval(address indexed owner, address indexed spender, uint256 value) +func (_Uniswap *UniswapFilterer) WatchApproval(opts *bind.WatchOpts, sink chan<- *UniswapApproval, owner []common.Address, spender []common.Address) (event.Subscription, error) { + + var ownerRule []interface{} + for _, ownerItem := range owner { + ownerRule = append(ownerRule, ownerItem) + } + var spenderRule []interface{} + for _, spenderItem := range spender { + spenderRule = append(spenderRule, spenderItem) + } + + logs, sub, err := _Uniswap.contract.WatchLogs(opts, "Approval", ownerRule, spenderRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(UniswapApproval) + if err := _Uniswap.contract.UnpackLog(event, "Approval", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseApproval is a log parse operation binding the contract event 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925. +// +// Solidity: event Approval(address indexed owner, address indexed spender, uint256 value) +func (_Uniswap *UniswapFilterer) ParseApproval(log types.Log) (*UniswapApproval, error) { + event := new(UniswapApproval) + if err := _Uniswap.contract.UnpackLog(event, "Approval", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// UniswapBurnIterator is returned from FilterBurn and is used to iterate over the raw logs and unpacked data for Burn events raised by the Uniswap contract. +type UniswapBurnIterator struct { + Event *UniswapBurn // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *UniswapBurnIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(UniswapBurn) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(UniswapBurn) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *UniswapBurnIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *UniswapBurnIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// UniswapBurn represents a Burn event raised by the Uniswap contract. +type UniswapBurn struct { + Sender common.Address + Amount0 *big.Int + Amount1 *big.Int + To common.Address + Raw types.Log // Blockchain specific contextual infos +} + +// FilterBurn is a free log retrieval operation binding the contract event 0xdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496. +// +// Solidity: event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to) +func (_Uniswap *UniswapFilterer) FilterBurn(opts *bind.FilterOpts, sender []common.Address, to []common.Address) (*UniswapBurnIterator, error) { + + var senderRule []interface{} + for _, senderItem := range sender { + senderRule = append(senderRule, senderItem) + } + + var toRule []interface{} + for _, toItem := range to { + toRule = append(toRule, toItem) + } + + logs, sub, err := _Uniswap.contract.FilterLogs(opts, "Burn", senderRule, toRule) + if err != nil { + return nil, err + } + return &UniswapBurnIterator{contract: _Uniswap.contract, event: "Burn", logs: logs, sub: sub}, nil +} + +// WatchBurn is a free log subscription operation binding the contract event 0xdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496. +// +// Solidity: event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to) +func (_Uniswap *UniswapFilterer) WatchBurn(opts *bind.WatchOpts, sink chan<- *UniswapBurn, sender []common.Address, to []common.Address) (event.Subscription, error) { + + var senderRule []interface{} + for _, senderItem := range sender { + senderRule = append(senderRule, senderItem) + } + + var toRule []interface{} + for _, toItem := range to { + toRule = append(toRule, toItem) + } + + logs, sub, err := _Uniswap.contract.WatchLogs(opts, "Burn", senderRule, toRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(UniswapBurn) + if err := _Uniswap.contract.UnpackLog(event, "Burn", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseBurn is a log parse operation binding the contract event 0xdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496. +// +// Solidity: event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to) +func (_Uniswap *UniswapFilterer) ParseBurn(log types.Log) (*UniswapBurn, error) { + event := new(UniswapBurn) + if err := _Uniswap.contract.UnpackLog(event, "Burn", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// UniswapMintIterator is returned from FilterMint and is used to iterate over the raw logs and unpacked data for Mint events raised by the Uniswap contract. +type UniswapMintIterator struct { + Event *UniswapMint // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *UniswapMintIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(UniswapMint) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(UniswapMint) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *UniswapMintIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *UniswapMintIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// UniswapMint represents a Mint event raised by the Uniswap contract. +type UniswapMint struct { + Sender common.Address + Amount0 *big.Int + Amount1 *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterMint is a free log retrieval operation binding the contract event 0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f. +// +// Solidity: event Mint(address indexed sender, uint256 amount0, uint256 amount1) +func (_Uniswap *UniswapFilterer) FilterMint(opts *bind.FilterOpts, sender []common.Address) (*UniswapMintIterator, error) { + + var senderRule []interface{} + for _, senderItem := range sender { + senderRule = append(senderRule, senderItem) + } + + logs, sub, err := _Uniswap.contract.FilterLogs(opts, "Mint", senderRule) + if err != nil { + return nil, err + } + return &UniswapMintIterator{contract: _Uniswap.contract, event: "Mint", logs: logs, sub: sub}, nil +} + +// WatchMint is a free log subscription operation binding the contract event 0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f. +// +// Solidity: event Mint(address indexed sender, uint256 amount0, uint256 amount1) +func (_Uniswap *UniswapFilterer) WatchMint(opts *bind.WatchOpts, sink chan<- *UniswapMint, sender []common.Address) (event.Subscription, error) { + + var senderRule []interface{} + for _, senderItem := range sender { + senderRule = append(senderRule, senderItem) + } + + logs, sub, err := _Uniswap.contract.WatchLogs(opts, "Mint", senderRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(UniswapMint) + if err := _Uniswap.contract.UnpackLog(event, "Mint", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseMint is a log parse operation binding the contract event 0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f. +// +// Solidity: event Mint(address indexed sender, uint256 amount0, uint256 amount1) +func (_Uniswap *UniswapFilterer) ParseMint(log types.Log) (*UniswapMint, error) { + event := new(UniswapMint) + if err := _Uniswap.contract.UnpackLog(event, "Mint", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// UniswapSwapIterator is returned from FilterSwap and is used to iterate over the raw logs and unpacked data for Swap events raised by the Uniswap contract. +type UniswapSwapIterator struct { + Event *UniswapSwap // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *UniswapSwapIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(UniswapSwap) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(UniswapSwap) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *UniswapSwapIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *UniswapSwapIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// UniswapSwap represents a Swap event raised by the Uniswap contract. +type UniswapSwap struct { + Sender common.Address + Amount0In *big.Int + Amount1In *big.Int + Amount0Out *big.Int + Amount1Out *big.Int + To common.Address + Raw types.Log // Blockchain specific contextual infos +} + +// FilterSwap is a free log retrieval operation binding the contract event 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822. +// +// Solidity: event Swap(address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to) +func (_Uniswap *UniswapFilterer) FilterSwap(opts *bind.FilterOpts, sender []common.Address, to []common.Address) (*UniswapSwapIterator, error) { + + var senderRule []interface{} + for _, senderItem := range sender { + senderRule = append(senderRule, senderItem) + } + + var toRule []interface{} + for _, toItem := range to { + toRule = append(toRule, toItem) + } + + logs, sub, err := _Uniswap.contract.FilterLogs(opts, "Swap", senderRule, toRule) + if err != nil { + return nil, err + } + return &UniswapSwapIterator{contract: _Uniswap.contract, event: "Swap", logs: logs, sub: sub}, nil +} + +// WatchSwap is a free log subscription operation binding the contract event 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822. +// +// Solidity: event Swap(address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to) +func (_Uniswap *UniswapFilterer) WatchSwap(opts *bind.WatchOpts, sink chan<- *UniswapSwap, sender []common.Address, to []common.Address) (event.Subscription, error) { + + var senderRule []interface{} + for _, senderItem := range sender { + senderRule = append(senderRule, senderItem) + } + + var toRule []interface{} + for _, toItem := range to { + toRule = append(toRule, toItem) + } + + logs, sub, err := _Uniswap.contract.WatchLogs(opts, "Swap", senderRule, toRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(UniswapSwap) + if err := _Uniswap.contract.UnpackLog(event, "Swap", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseSwap is a log parse operation binding the contract event 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822. +// +// Solidity: event Swap(address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to) +func (_Uniswap *UniswapFilterer) ParseSwap(log types.Log) (*UniswapSwap, error) { + event := new(UniswapSwap) + if err := _Uniswap.contract.UnpackLog(event, "Swap", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// UniswapSyncIterator is returned from FilterSync and is used to iterate over the raw logs and unpacked data for Sync events raised by the Uniswap contract. +type UniswapSyncIterator struct { + Event *UniswapSync // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *UniswapSyncIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(UniswapSync) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(UniswapSync) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *UniswapSyncIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *UniswapSyncIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// UniswapSync represents a Sync event raised by the Uniswap contract. +type UniswapSync struct { + Reserve0 *big.Int + Reserve1 *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterSync is a free log retrieval operation binding the contract event 0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1. +// +// Solidity: event Sync(uint112 reserve0, uint112 reserve1) +func (_Uniswap *UniswapFilterer) FilterSync(opts *bind.FilterOpts) (*UniswapSyncIterator, error) { + + logs, sub, err := _Uniswap.contract.FilterLogs(opts, "Sync") + if err != nil { + return nil, err + } + return &UniswapSyncIterator{contract: _Uniswap.contract, event: "Sync", logs: logs, sub: sub}, nil +} + +// WatchSync is a free log subscription operation binding the contract event 0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1. +// +// Solidity: event Sync(uint112 reserve0, uint112 reserve1) +func (_Uniswap *UniswapFilterer) WatchSync(opts *bind.WatchOpts, sink chan<- *UniswapSync) (event.Subscription, error) { + + logs, sub, err := _Uniswap.contract.WatchLogs(opts, "Sync") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(UniswapSync) + if err := _Uniswap.contract.UnpackLog(event, "Sync", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseSync is a log parse operation binding the contract event 0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1. +// +// Solidity: event Sync(uint112 reserve0, uint112 reserve1) +func (_Uniswap *UniswapFilterer) ParseSync(log types.Log) (*UniswapSync, error) { + event := new(UniswapSync) + if err := _Uniswap.contract.UnpackLog(event, "Sync", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// UniswapTransferIterator is returned from FilterTransfer and is used to iterate over the raw logs and unpacked data for Transfer events raised by the Uniswap contract. +type UniswapTransferIterator struct { + Event *UniswapTransfer // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *UniswapTransferIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(UniswapTransfer) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(UniswapTransfer) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *UniswapTransferIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *UniswapTransferIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// UniswapTransfer represents a Transfer event raised by the Uniswap contract. +type UniswapTransfer struct { + From common.Address + To common.Address + Value *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterTransfer is a free log retrieval operation binding the contract event 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef. +// +// Solidity: event Transfer(address indexed from, address indexed to, uint256 value) +func (_Uniswap *UniswapFilterer) FilterTransfer(opts *bind.FilterOpts, from []common.Address, to []common.Address) (*UniswapTransferIterator, error) { + + var fromRule []interface{} + for _, fromItem := range from { + fromRule = append(fromRule, fromItem) + } + var toRule []interface{} + for _, toItem := range to { + toRule = append(toRule, toItem) + } + + logs, sub, err := _Uniswap.contract.FilterLogs(opts, "Transfer", fromRule, toRule) + if err != nil { + return nil, err + } + return &UniswapTransferIterator{contract: _Uniswap.contract, event: "Transfer", logs: logs, sub: sub}, nil +} + +// WatchTransfer is a free log subscription operation binding the contract event 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef. +// +// Solidity: event Transfer(address indexed from, address indexed to, uint256 value) +func (_Uniswap *UniswapFilterer) WatchTransfer(opts *bind.WatchOpts, sink chan<- *UniswapTransfer, from []common.Address, to []common.Address) (event.Subscription, error) { + + var fromRule []interface{} + for _, fromItem := range from { + fromRule = append(fromRule, fromItem) + } + var toRule []interface{} + for _, toItem := range to { + toRule = append(toRule, toItem) + } + + logs, sub, err := _Uniswap.contract.WatchLogs(opts, "Transfer", fromRule, toRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(UniswapTransfer) + if err := _Uniswap.contract.UnpackLog(event, "Transfer", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseTransfer is a log parse operation binding the contract event 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef. +// +// Solidity: event Transfer(address indexed from, address indexed to, uint256 value) +func (_Uniswap *UniswapFilterer) ParseTransfer(log types.Log) (*UniswapTransfer, error) { + event := new(UniswapTransfer) + if err := _Uniswap.contract.UnpackLog(event, "Transfer", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} diff --git a/pkg/liquidity-source/uniswap-v2/pool_tracker.go b/pkg/liquidity-source/uniswap-v2/pool_tracker.go index f1bb2eada..1dcbb5ae9 100644 --- a/pkg/liquidity-source/uniswap-v2/pool_tracker.go +++ b/pkg/liquidity-source/uniswap-v2/pool_tracker.go @@ -2,13 +2,13 @@ package uniswapv2 import ( "context" - "encoding/json" "math/big" "time" "github.com/KyberNetwork/ethrpc" "github.com/KyberNetwork/logger" "github.com/ethereum/go-ethereum/core/types" + "github.com/goccy/go-json" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" @@ -64,7 +64,7 @@ func (d *PoolTracker) GetNewPoolState( return p, err } - if p.BlockNumber > blockNumber.Uint64() { + if blockNumber != nil && p.BlockNumber > blockNumber.Uint64() { logger. WithFields( logger.Fields{ @@ -86,8 +86,10 @@ func (d *PoolTracker) GetNewPoolState( WithFields( logger.Fields{ "pool_id": p.Address, - "old_reserve": p.Reserves, - "new_reserve": reserveData, + "old_reserve_0": p.Reserves[0], + "old_reserve_1": p.Reserves[1], + "new_reserve_0": reserveData.Reserve0.String(), + "new_reserve_1": reserveData.Reserve1.String(), "old_block_number": p.BlockNumber, "new_block_number": blockNumber, "duration_ms": time.Since(startTime).Milliseconds(), diff --git a/pkg/liquidity-source/woofi-v2/pool_simulator.go b/pkg/liquidity-source/woofi-v2/pool_simulator.go index eff4bcde8..6f7c21852 100644 --- a/pkg/liquidity-source/woofi-v2/pool_simulator.go +++ b/pkg/liquidity-source/woofi-v2/pool_simulator.go @@ -1,7 +1,6 @@ package woofiv2 import ( - "encoding/json" "errors" "fmt" "time" @@ -10,6 +9,7 @@ import ( "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" poolpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/logger" + "github.com/goccy/go-json" "github.com/holiman/uint256" ) diff --git a/pkg/liquidity-source/woofi-v2/pool_tracker.go b/pkg/liquidity-source/woofi-v2/pool_tracker.go index ff35ac432..fae8ea578 100644 --- a/pkg/liquidity-source/woofi-v2/pool_tracker.go +++ b/pkg/liquidity-source/woofi-v2/pool_tracker.go @@ -2,19 +2,19 @@ package woofiv2 import ( "context" - "encoding/json" "errors" "math/big" "strings" "time" + "github.com/KyberNetwork/ethrpc" + "github.com/KyberNetwork/logger" + "github.com/ethereum/go-ethereum/common" + "github.com/goccy/go-json" "github.com/holiman/uint256" - "github.com/KyberNetwork/ethrpc" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" - "github.com/KyberNetwork/logger" - "github.com/ethereum/go-ethereum/common" ) type PoolTracker struct {