diff --git a/common/ethereum/amm/abi.go b/common/ethereum/amm/abi.go index 13bf99ee0..144fa3f6e 100644 --- a/common/ethereum/amm/abi.go +++ b/common/ethereum/amm/abi.go @@ -4,12 +4,13 @@ import ( "fmt" "math/big" - ethAbi "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/ethereum/go-ethereum/common" ethCommon "github.com/fluidity-money/fluidity-app/common/ethereum" "github.com/fluidity-money/fluidity-app/lib/types/ethereum" ethTypes "github.com/fluidity-money/fluidity-app/lib/types/ethereum" "github.com/fluidity-money/fluidity-app/lib/types/misc" + + ethAbi "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" ) const ammAbiString = `[ @@ -17,7 +18,8 @@ const ammAbiString = `[ "anonymous": false, "inputs": [ { "indexed": true, "internalType": "uint256", "name": "id", "type": "uint256" }, - { "indexed": false, "internalType": "int128", "name": "delta", "type": "int128" } + { "indexed": false, "internalType": "int256", "name": "token0", "type": "int256" }, + { "indexed": false, "internalType": "int256", "name": "token1", "type": "int256" } ], "name": "UpdatePositionLiquidity", "type": "event" @@ -82,13 +84,14 @@ var AmmAbi ethAbi.ABI type ( AmmEventPositionMint struct { Id misc.BigInt `json:"id"` + Pool ethereum.Address `json:"pool"` Lower int32 `json:"lower_tick"` Upper int32 `json:"upper_tick"` - Pool ethereum.Address `json:"pool"` } AmmEventPositionUpdate struct { - Id misc.BigInt `json:"id"` - Delta misc.BigInt `json:"liquidity_delta"` + Id misc.BigInt `json:"id"` + Token0 misc.BigInt `json:"token0"` + Token1 misc.BigInt `json:"token1"` } AmmEventCollectFees struct { Id misc.BigInt @@ -187,15 +190,26 @@ func DecodeUpdatePosition(log ethTypes.Log) (update AmmEventPositionUpdate, err return } - delta, err := ethCommon.CoerceBoundContractResultsToInt(data) + token0, ok := data[0].(*big.Int) + + if !ok { + err = fmt.Errorf("Failed to decode token0! %T", data[0]) + + return + } + + token1, ok := data[1].(*big.Int) + + if !ok { + err = fmt.Errorf("Failed to decode token1! %T", data[1]) - if err != nil { return } update = AmmEventPositionUpdate{ - Id: misc.NewBigIntFromInt(*id), - Delta: misc.NewBigIntFromInt(*delta), + Id: misc.NewBigIntFromInt(*id), + Token0: misc.NewBigIntFromInt(*token0), + Token1: misc.NewBigIntFromInt(*token1), } return update, nil diff --git a/common/ethereum/amm/abi_test.go b/common/ethereum/amm/abi_test.go new file mode 100644 index 000000000..b44e5d2d9 --- /dev/null +++ b/common/ethereum/amm/abi_test.go @@ -0,0 +1,48 @@ +package amm + +import ( + "testing" + "encoding/hex" + + "github.com/fluidity-money/fluidity-app/lib/types/ethereum" + "github.com/fluidity-money/fluidity-app/lib/types/misc" + + "github.com/stretchr/testify/assert" +) + +func TestDecodeUpdatePosition(t *testing.T) { + b, err := hex.DecodeString("0000000000000000000000000000000000000000000000000dc051fbd4b4a1ca00000000000000000000000000000000000000000000000000000000d47a19cc") + assert.Nil(t, err) + u, err := DecodeUpdatePosition(ethereum.Log{ + Topics: []ethereum.Hash{ + ethereum.HashFromString("0x555c5816cc24ae6b4a85b2e02a07ebc514a04639a07694f29ff9a0de9b650987"), + ethereum.HashFromString("0x0000000000000000000000000000000000000000000000000000000000000000"), + }, + Data: misc.Blob(b), + }) + assert.Nil(t, err) + //assert.Equalf(t, misc.BigIntFromInt(0), u.Id, "id not equal") + assert.Equalf(t, misc.BigIntFromInt64(990882060068757962), u.Token0, "token0 not equal") + assert.Equalf(t, misc.BigIntFromInt64(3564771788), u.Token1, "token1 not equal") +} + +func TestMintPosition(t *testing.T) { + b, err := hex.DecodeString("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd00e4fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd08a0") + assert.Nil(t, err) + m, err := DecodeMint(ethereum.Log{ + Topics: []ethereum.Hash{ + ethereum.HashFromString("0x7b0f5059c07211d90c2400fc99ac93e0e56db5168afa91f60d178bb6dc1c73f0"), + ethereum.HashFromString("0x0000000000000000000000000000000000000000000000000000000000000000"), + ethereum.HashFromString("0x000000000000000000000000feb6034fc7df27df18a3a6bad5fb94c0d3dcb6d5"), + ethereum.HashFromString("0x00000000000000000000000022b9fa698b68bba071b513959794e9a47d19214c"), + }, + Data: misc.Blob(b), + }) + assert.Nil(t, err) + //assert.Equalf(t, misc.BigIntFromInt(0), m.Id, "id not the same") + assert.Equalf(t, + ethereum.AddressFromString("0x22b9fa698b68bba071b513959794e9a47d19214c"), + m.Pool, + "pool not correct", + ) +} diff --git a/contracts/ethereum/contracts/AutoIncreaseLiquidityProvider.sol b/contracts/ethereum/contracts/AutoIncreaseLiquidityProvider.sol index 38cb12cfd..d49271f55 100644 --- a/contracts/ethereum/contracts/AutoIncreaseLiquidityProvider.sol +++ b/contracts/ethereum/contracts/AutoIncreaseLiquidityProvider.sol @@ -33,6 +33,8 @@ contract AutoIncreaseLiquidityProvider is ILiquidityProvider { /// @dev amountTaken_ from the pool so far uint256 public amountTaken_; + uint256 public amountAdded_; + /** * @notice initialiser function * @@ -57,7 +59,8 @@ contract AutoIncreaseLiquidityProvider is ILiquidityProvider { } /// @inheritdoc ILiquidityProvider - function addToPool(uint /* _amount */) external view { + function addToPool(uint _amount) external { + amountAdded_ += _amount; } /// @inheritdoc ILiquidityProvider @@ -71,7 +74,7 @@ contract AutoIncreaseLiquidityProvider is ILiquidityProvider { function totalPoolAmount() external view returns (uint) { uint secsSince = block.timestamp - deploymentTs_; uint256 fluidBalance = (secsSince * increaseAmount_) - amountTaken_; - return fluidBalance; + return fluidBalance + amountAdded_; } function owner_() public view returns (address) {