-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Develop support superposition more (#2685)
* New shape for AMM * Do a lookup to restore the functionality with the amm delta
- Loading branch information
Showing
6 changed files
with
196 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
{ | ||
"type": "function", | ||
"name": "positionLiquidity8D11C045", | ||
"inputs": [ | ||
{ | ||
"name": "pool", | ||
"type": "address", | ||
"internalType": "address" | ||
}, | ||
{ | ||
"name": "id", | ||
"type": "uint256", | ||
"internalType": "uint256" | ||
} | ||
], | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "uint128", | ||
"internalType": "uint128" | ||
} | ||
], | ||
"stateMutability": "nonpayable" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2022 Fluidity Money. All rights reserved. Use of this | ||
// source code is governed by a GPL-style license that can be found in the | ||
// LICENSE.md file. | ||
|
||
package longtail | ||
|
||
import ( | ||
"bytes" | ||
|
||
ethAbi "github.com/ethereum/go-ethereum/accounts/abi" | ||
) | ||
|
||
func init() { | ||
longtailReader := bytes.NewBuffer(longtailBytes) | ||
|
||
var err error | ||
|
||
if longtailAbi, err = ethAbi.JSON(longtailReader); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2022 Fluidity Money. All rights reserved. Use of this | ||
// source code is governed by a GPL-style license that can be found in the | ||
// LICENSE.md file. | ||
|
||
package longtail | ||
|
||
import ( | ||
_ "embed" | ||
"math/big" | ||
|
||
"github.com/fluidity-money/fluidity-app/common/ethereum" | ||
"github.com/fluidity-money/fluidity-app/lib/log" | ||
"github.com/fluidity-money/fluidity-app/lib/types/misc" | ||
libEth "github.com/fluidity-money/fluidity-app/lib/types/ethereum" | ||
|
||
ethAbi "github.com/ethereum/go-ethereum/accounts/abi" | ||
ethCommon "github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
) | ||
|
||
// Context for logging | ||
const Context = "LONGTAIL" | ||
|
||
//go:embed abi.json | ||
var longtailBytes []byte | ||
|
||
var longtailAbi ethAbi.ABI | ||
|
||
// GetPositionLiquidity for a pool and position ID given | ||
func GetPositionLiquidity(client *ethclient.Client, amm_, pool_ libEth.Address, id misc.BigInt) misc.BigInt { | ||
var ( | ||
amm = ethCommon.HexToAddress(amm_.String()) | ||
pool = ethCommon.HexToAddress(pool_.String()) | ||
) | ||
log.Debug(func(k *log.Log) { | ||
k.Context = Context | ||
|
||
k.Format( | ||
"Using the Longtail AMM pool %v to get a position's liquidity", | ||
pool, | ||
) | ||
|
||
k.Payload = id | ||
}) | ||
|
||
resp, err := ethereum.StaticCall( | ||
client, | ||
amm, | ||
longtailAbi, | ||
"positionLiquidity8D11C045", | ||
pool, | ||
id, | ||
) | ||
|
||
if err != nil { | ||
log.Fatal(func(k *log.Log) { | ||
k.Context = Context | ||
|
||
k.Format( | ||
"Failed to do a static call to positionLiquidity8D11C045! Pool address %v, id %v", | ||
pool, | ||
id, | ||
) | ||
|
||
k.Payload = err | ||
}) | ||
} | ||
|
||
liquidity, ok := resp[0].(*big.Int) | ||
|
||
if !ok { | ||
log.Fatal(func(k *log.Log) { | ||
k.Context = Context | ||
k.Format("Incorrect position liquidity type %T", resp[0]) | ||
}) | ||
} | ||
|
||
return misc.NewBigIntFromInt(*liquidity) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters