Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[e2e][CL]: pool migration #4690

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
82adea8
update migration record
ThanhNhann Mar 21, 2023
67328a1
add process
ThanhNhann Mar 22, 2023
24d10c3
merge main
ThanhNhann Mar 27, 2023
203a98c
convert int to string
ThanhNhann Mar 27, 2023
e9198f1
add register amino
ThanhNhann Mar 28, 2023
ce69c56
Merge remote-tracking branch 'origin/main' into nhan/e2e_pool_migration
faddat May 7, 2023
9a73263
add changelog
faddat May 7, 2023
3cecb8f
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann May 22, 2023
1e560f6
update e2e cmd
ThanhNhann May 26, 2023
4588fad
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann May 26, 2023
c049d14
update using name
ThanhNhann May 29, 2023
107655f
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann May 30, 2023
a8b15a8
fix wrong denom and add more time to wait handle gov proposal
ThanhNhann Jun 1, 2023
639d151
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann Jun 1, 2023
df3dc38
add fee and gas for migrate command
ThanhNhann Jun 1, 2023
9ea6c3f
update cmd for unlock and migrate
ThanhNhann Jun 1, 2023
e8aa18d
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann Jun 1, 2023
437596f
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann Jun 1, 2023
807c6c2
add fee and gas for command
ThanhNhann Jun 1, 2023
f3a5d9f
update cmd migration to get and parse data
ThanhNhann Jun 2, 2023
ebb1fa3
add cmd query position
ThanhNhann Jun 3, 2023
0207880
add test_helper for migration
ThanhNhann Jun 3, 2023
ba9f95e
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann Jun 3, 2023
7064f20
fix wrong version
ThanhNhann Jun 3, 2023
5deb3a7
update helper e2e and cmd plus query
ThanhNhann Jun 3, 2023
3da9f52
lint
ThanhNhann Jun 3, 2023
b99bc99
add test for validateMigrateResult
ThanhNhann Jun 4, 2023
fd7894a
update test pool migration
ThanhNhann Jun 4, 2023
67d2e5b
add case SuperfluidBonded for test migration
ThanhNhann Jun 4, 2023
1829d95
update check PermissionlessCreation
ThanhNhann Jun 5, 2023
9a280b5
update posistion query and changlog
ThanhNhann Jun 5, 2023
082752d
add checking time pass of EnableSuperfluidAsset
ThanhNhann Jun 8, 2023
898e018
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann Jun 8, 2023
94dfcfc
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann Jun 8, 2023
020645f
fix error address
ThanhNhann Jun 8, 2023
aefc68b
done 4 cases migration
ThanhNhann Jun 9, 2023
8727de6
update get lockId TestSuperfluidVoting
ThanhNhann Jun 10, 2023
c32c0db
add more test for migration
ThanhNhann Jun 11, 2023
4777b50
more test
ThanhNhann Jun 11, 2023
801b425
fix ci
ThanhNhann Jun 11, 2023
09ccc31
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann Jun 11, 2023
2697a19
update logic QueryPositionById
ThanhNhann Jun 12, 2023
c9d4b0c
lint
ThanhNhann Jun 12, 2023
82004a5
more lint
ThanhNhann Jun 12, 2023
bf6c947
clean
ThanhNhann Jun 20, 2023
79ca6e1
update code by reviews of matt
ThanhNhann Jun 20, 2023
6100b0a
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann Jun 20, 2023
ef4145f
Add inline comments
mattverse Jun 21, 2023
38a4b2b
add more checking
ThanhNhann Jun 22, 2023
5034937
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann Jun 22, 2023
ad6fa46
change min tick
ThanhNhann Jun 22, 2023
1cf4b0a
update code with reviews of adam
ThanhNhann Jun 22, 2023
65c3e8f
fix compare wrong type
ThanhNhann Jun 22, 2023
ebdd197
fix convert type int to dec
ThanhNhann Jun 22, 2023
f618a5b
add 2 cases migration test
ThanhNhann Jun 22, 2023
5dc8ab5
Update godoc
ThanhNhann Jun 22, 2023
7c35040
update code with reviews of adam
ThanhNhann Jun 23, 2023
e758014
Merge branch 'main' of https://github.com/osmosis-labs/osmosis into n…
ThanhNhann Jun 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/e2e/configurer/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ func (c *Config) EnableSuperfluidAsset(denom string) {
for _, node := range c.NodeConfigs {
node.VoteYesProposal(initialization.ValidatorWalletName, c.LatestProposalNumber)
}
require.Eventually(c.t, func() bool {
status, err := chain.QueryPropStatus(c.LatestProposalNumber)
if err != nil {
return false
}
return status == proposalStatusPassed
}, time.Second*30, time.Millisecond*500)
}

func (c *Config) LockAndAddToExistingLock(amount sdk.Int, denom, lockupWalletAddr, lockupWalletSuperfluidAddr string) {
Expand Down
245 changes: 241 additions & 4 deletions tests/e2e/configurer/chain/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/tendermint/tendermint/p2p"
coretypes "github.com/tendermint/tendermint/rpc/core/types"

"github.com/osmosis-labs/osmosis/osmoutils/osmocli"
app "github.com/osmosis-labs/osmosis/v16/app"
)

Expand Down Expand Up @@ -89,7 +90,7 @@ func (n *NodeConfig) CreateConcentratedPosition(from, lowerTick, upperTick strin
n.LogActionF("creating concentrated position")
// gas = 50,000 because e2e default to 40,000, we hardcoded extra 10k gas to initialize tick
// fees = 1250 (because 50,000 * 0.0025 = 1250)
cmd := []string{"osmosisd", "tx", "concentratedliquidity", "create-position", fmt.Sprint(poolId), lowerTick, upperTick, tokens, fmt.Sprintf("%d", token0MinAmt), fmt.Sprintf("%d", token1MinAmt), fmt.Sprintf("--from=%s", from), "--gas=500000", "--fees=1250uosmo", "-o json"}
cmd := []string{"osmosisd", "tx", "concentratedliquidity", "create-position", fmt.Sprint(poolId), lowerTick, upperTick, tokens, fmt.Sprintf("%d", token0MinAmt), fmt.Sprintf("%d", token1MinAmt), fmt.Sprintf("--from=%s", from), "--gas=600000", "--fees=1500uosmo", "-o json"}
outJson, _, err := n.containerManager.ExecTxCmdWithSuccessString(n.t, n.chainId, n.Name, cmd, "code\":0")
require.NoError(n.t, err)

Expand Down Expand Up @@ -244,6 +245,14 @@ func (n *NodeConfig) JoinPoolExactAmountIn(tokenIn string, poolId uint64, shareO
n.LogActionF("successfully joined pool")
}

func (n *NodeConfig) JoinPoolNoSwap(from string, poolId uint64, shareAmountOut string, maxAmountsIn string) {
n.LogActionF("Join pool no swap")
cmd := []string{"osmosisd", "tx", "gamm", "join-pool", fmt.Sprintf("--pool-id=%d", poolId), fmt.Sprintf("--share-amount-out=%s", shareAmountOut), fmt.Sprintf("--max-amounts-in=%s", maxAmountsIn), fmt.Sprintf("--from=%s", from)}
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
require.NoError(n.t, err)
n.LogActionF("successfully joined pool no swap")
}

func (n *NodeConfig) ExitPool(from, minAmountsOut string, poolId uint64, shareAmountIn string) {
n.LogActionF("exiting gamm pool")
cmd := []string{"osmosisd", "tx", "gamm", "exit-pool", fmt.Sprintf("--min-amounts-out=%s", minAmountsOut), fmt.Sprintf("--share-amount-in=%s", shareAmountIn), fmt.Sprintf("--pool-id=%d", poolId), fmt.Sprintf("--from=%s", from)}
Expand All @@ -252,6 +261,47 @@ func (n *NodeConfig) ExitPool(from, minAmountsOut string, poolId uint64, shareAm
n.LogActionF("successfully exited pool %d, minAmountsOut %s, shareAmountIn %s", poolId, minAmountsOut, shareAmountIn)
}

func (n *NodeConfig) UnlockAndMigrateSharesToFullRangeConcentratedPosition(from, lock_id, minAmountsOut string, sharesToMigrate string) (positionId uint64, amount0, amount1 sdk.Int, liquidity sdk.Dec, poolIdLeaving, poolIdEntering, concentratedLockId uint64) {
n.LogActionF("Unlock and migrate shares to full range Concentrated position")
cmd := []string{"osmosisd", "tx", "superfluid", "unlock-and-migrate-to-cl", lock_id, sharesToMigrate, minAmountsOut, fmt.Sprintf("--from=%s", from), "--gas=1500000", "--fees=3750uosmo", "-o json"}
outJson, _, err := n.containerManager.ExecTxCmdWithSuccessString(n.t, n.chainId, n.Name, cmd, "code\":0")
require.NoError(n.t, err)

var txResponse map[string]interface{}
err = json.Unmarshal(outJson.Bytes(), &txResponse)
require.NoError(n.t, err)

data, err := GetDataReponseUnlockAndMigrateSharesToFullRangeConcentratedPosition(txResponse)
require.NoError(n.t, err)
positionIdString, amount0String, amount1String, liquidityString, poolIdLeavingString, poolIdEnteringString, concentratedLockIdString := data[0], data[1], data[2], data[3], data[4], data[5], data[6]

positionId, err = osmocli.ParseUint(positionIdString, "")
require.NoError(n.t, err)

amount0Int, err := osmocli.ParseInt(amount0String, "")
require.NoError(n.t, err)
amount0 = sdk.NewInt(amount0Int)

amount1Int, err := osmocli.ParseInt(amount1String, "")
require.NoError(n.t, err)
amount1 = sdk.NewInt(amount1Int)

liquidity = sdk.MustNewDecFromStr(liquidityString)

poolIdLeaving, err = osmocli.ParseUint(poolIdLeavingString, "")
require.NoError(n.t, err)

poolIdEntering, err = osmocli.ParseUint(poolIdEnteringString, "")
require.NoError(n.t, err)

concentratedLockId, err = osmocli.ParseUint(concentratedLockIdString, "")
require.NoError(n.t, err)

n.LogActionF("successfully unlock and migrate shares")

return positionId, amount0, amount1, liquidity, poolIdLeaving, poolIdEntering, concentratedLockId
}

func (n *NodeConfig) SubmitUpgradeProposal(upgradeVersion string, upgradeHeight int64, initialDeposit sdk.Coin) {
n.LogActionF("submitting upgrade proposal %s for height %d", upgradeVersion, upgradeHeight)
cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "software-upgrade", upgradeVersion, fmt.Sprintf("--title=\"%s upgrade\"", upgradeVersion), "--description=\"upgrade proposal submission\"", fmt.Sprintf("--upgrade-height=%d", upgradeHeight), "--upgrade-info=\"\"", "--from=val", fmt.Sprintf("--deposit=%s", initialDeposit)}
Expand Down Expand Up @@ -287,6 +337,22 @@ func (n *NodeConfig) SubmitTextProposal(text string, initialDeposit sdk.Coin, is
n.LogActionF("successfully submitted text gov proposal")
}

func (n *NodeConfig) SubmitUpdateMigrationRecordsProposal(records string, initialDeposit sdk.Coin) {
n.LogActionF("submit update migration record")
cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "update-migration-records-proposal", fmt.Sprintf("--migration-records=%s", records), fmt.Sprintf("--title=\"%s migration-records\"", records), fmt.Sprintf("--description=\"%s update migration records\"", records), "--from=val", fmt.Sprintf("--deposit=%s", initialDeposit)}
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
require.NoError(n.t, err)
n.LogActionF("successfully submitted update migration records proposal for record %s", records)
}

func (n *NodeConfig) SubmitReplaceMigrationRecordsProposal(records string, initialDeposit sdk.Coin) {
n.LogActionF("submit replace migration record")
cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "replace-migration-records-proposal", fmt.Sprintf("--migration-records=%s", records), fmt.Sprintf("--title=\"%s migration-records\"", records), fmt.Sprintf("--description=\"%s replace migration records\"", records), "--from=val", fmt.Sprintf("--deposit=%s", initialDeposit)}
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
require.NoError(n.t, err)
n.LogActionF("successfully submitted replace migration records proposal for record %s", records)
}

func (n *NodeConfig) SubmitTickSpacingReductionProposal(poolTickSpacingRecords string, initialDeposit sdk.Coin, isExpedited bool) {
n.LogActionF("submitting tick spacing reduction gov proposal")
cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "tick-spacing-decrease-proposal", "--title=\"test tick spacing reduction proposal title\"", "--description=\"test tick spacing reduction proposal\"", "--from=val", fmt.Sprintf("--deposit=%s", initialDeposit), fmt.Sprintf("--pool-tick-spacing-records=%s", poolTickSpacingRecords)}
Expand Down Expand Up @@ -326,12 +392,25 @@ func (n *NodeConfig) VoteNoProposal(from string, proposalNumber int) {
n.LogActionF("successfully voted no on proposal: %d", proposalNumber)
}

func (n *NodeConfig) LockTokens(tokens string, duration string, from string) {
func (n *NodeConfig) LockTokens(tokens string, duration string, from string) uint64 {
n.LogActionF("locking %s for %s", tokens, duration)
cmd := []string{"osmosisd", "tx", "lockup", "lock-tokens", tokens, fmt.Sprintf("--duration=%s", duration), fmt.Sprintf("--from=%s", from)}
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
cmd := []string{"osmosisd", "tx", "lockup", "lock-tokens", tokens, fmt.Sprintf("--duration=%s", duration), fmt.Sprintf("--from=%s", from), "-o json"}
outJson, _, err := n.containerManager.ExecTxCmdWithSuccessString(n.t, n.chainId, n.Name, cmd, "code\":0")
require.NoError(n.t, err)

var txResponse map[string]interface{}
err = json.Unmarshal(outJson.Bytes(), &txResponse)
require.NoError(n.t, err)

periodLockIDString, err := GetPeriodLockIDFromResponse(txResponse)
require.NoError(n.t, err)

periodLockID, err := strconv.ParseUint(periodLockIDString, 10, 64)
require.NoError(n.t, err)

n.LogActionF("successfully created lock")

return periodLockID
}

func (n *NodeConfig) AddToExistingLock(tokens sdk.Int, denom, duration, from string) {
Expand Down Expand Up @@ -383,6 +462,33 @@ func (n *NodeConfig) SuperfluidDelegate(lockNumber int, valAddress string, from
n.LogActionF("successfully superfluid delegated lock %s to %s", lockStr, valAddress)
}

func (n *NodeConfig) SuperfluidUndelegate(lockNumber int, from string) {
lockStr := strconv.Itoa(lockNumber)
n.LogActionF("superfluid undelegating a lock %s from a validator", lockStr)
cmd := []string{"osmosisd", "tx", "superfluid", "undelegate", lockStr, fmt.Sprintf("--from=%s", from)}
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
require.NoError(n.t, err)
n.LogActionF("successfully superfluid undelegated a lock %s from a validator", lockStr)
}

func (n *NodeConfig) SuperfluidUnbondLock(lockNumber int, from string) {
lockStr := strconv.Itoa(lockNumber)
n.LogActionF("superfluid unbond lock that has been superfluid staked")
cmd := []string{"osmosisd", "tx", "superfluid", "unbond-lock", lockStr, fmt.Sprintf("--from=%s", from)}
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
require.NoError(n.t, err)
n.LogActionF("successfully superfluid unbond lock that has been superfluid staked")
}

func (n *NodeConfig) LockupBeginUnlock(lockNumber int, from string, coins string) {
lockStr := strconv.Itoa(lockNumber)
n.LogActionF("lockup begin unlock individual period lock by ID")
cmd := []string{"osmosisd", "tx", "lockup", "begin-unlock-by-id", lockStr, fmt.Sprintf("--amount=%s", coins), fmt.Sprintf("--from=%s", from)}
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
require.NoError(n.t, err)
n.LogActionF("successfully lockup begin unlock individual period lock by ID")
}

func (n *NodeConfig) BankSend(amount string, sendAddress string, receiveAddress string) {
n.LogActionF("bank sending %s from address %s to %s", amount, sendAddress, receiveAddress)
cmd := []string{"osmosisd", "tx", "bank", "send", sendAddress, receiveAddress, amount, "--from=val"}
Expand Down Expand Up @@ -532,3 +638,134 @@ func GetPositionID(responseJson map[string]interface{}) (string, error) {

return "", fmt.Errorf("position_id field not found in response")
}

func GetDataReponseUnlockAndMigrateSharesToFullRangeConcentratedPosition(responseJson map[string]interface{}) ([]string, error) {
var result [7]string

logs, ok := responseJson["logs"].([]interface{})
if !ok {
return nil, fmt.Errorf("logs field not found in response")
}

if len(logs) == 0 {
return nil, fmt.Errorf("empty logs field in response")
}

log, ok := logs[0].(map[string]interface{})
if !ok {
return nil, fmt.Errorf("invalid format of logs field")
}

events, ok := log["events"].([]interface{})
if !ok {
return nil, fmt.Errorf("events field not found in logs")
}

for _, event := range events {
attributes, ok := event.(map[string]interface{})["attributes"].([]interface{})
if !ok {
return nil, fmt.Errorf("attributes field not found in event")
}

for _, attr := range attributes {
switch v := attr.(type) {
case map[string]interface{}:
if v["key"] == "position_id" {
positionId, ok := v["value"].(string)
if !ok {
return nil, fmt.Errorf("invalid format of position_id field")
}
result[0] = positionId
} else if v["key"] == "amount0" {
amount0, ok := v["value"].(string)
if !ok {
return nil, fmt.Errorf("invalid format of amount0 field")
}
result[1] = amount0
} else if v["key"] == "amount1" {
amount1, ok := v["value"].(string)
if !ok {
return nil, fmt.Errorf("invalid format of amount1 field")
}
result[2] = amount1
} else if v["key"] == "liquidity" {
liquidity, ok := v["value"].(string)
if !ok {
return nil, fmt.Errorf("invalid format of amount1 field")
}
result[3] = liquidity
} else if v["key"] == "pool_id_leaving" {
poolIdLeaving, ok := v["value"].(string)
if !ok {
return nil, fmt.Errorf("invalid format of poolIdLeaving field")
}
result[4] = poolIdLeaving
} else if v["key"] == "pool_id_entering" {
poolIdEntering, ok := v["value"].(string)
if !ok {
return nil, fmt.Errorf("invalid format of poolIdEntering field")
}
result[5] = poolIdEntering
} else if v["key"] == "concentrated_lock_id" {
concentratedLockId, ok := v["value"].(string)
if !ok {
return nil, fmt.Errorf("invalid format of concentratedLockId field")
}
result[6] = concentratedLockId
}
if result[0] != "" && result[6] != "" && result[4] != "" {
return result[:], nil
}
default:
return nil, fmt.Errorf("invalid type for attributes field")
}
}
}

return nil, fmt.Errorf("position_id field not found in response")
}

func GetPeriodLockIDFromResponse(responseJson map[string]interface{}) (string, error) {
logs, ok := responseJson["logs"].([]interface{})
if !ok {
return "", fmt.Errorf("logs field not found in response")
}

if len(logs) == 0 {
return "", fmt.Errorf("empty logs field in response")
}

log, ok := logs[0].(map[string]interface{})
if !ok {
return "", fmt.Errorf("invalid format of logs field")
}

events, ok := log["events"].([]interface{})
if !ok {
return "", fmt.Errorf("events field not found in logs")
}

for _, event := range events {
attributes, ok := event.(map[string]interface{})["attributes"].([]interface{})
if !ok {
return "", fmt.Errorf("attributes field not found in event")
}

for _, attr := range attributes {
switch v := attr.(type) {
case map[string]interface{}:
if v["key"] == "period_lock_id" {
positionID, ok := v["value"].(string)
if !ok {
return "", fmt.Errorf("invalid format of period_lock_id field")
}
return positionID, nil
}
default:
return "", fmt.Errorf("invalid type for attributes field")
ThanhNhann marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

return "", fmt.Errorf("period_lock_id field not found in response")
}
Loading