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

[future] Move core-1 vesting -> contracts #660

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 5 additions & 6 deletions .github/workflows/interchaintest-E2E.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- '**.sum'

env:
REGISTRY: ghcr.io
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-e2e
GO_VERSION: 1.19

Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Download dependencies
run: |
go mod download
Expand Down Expand Up @@ -77,10 +77,10 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max

# make juno:branchname here for all needs.build-and-push-image.outputs.branchTag
# then upload to github. Then download for each as a cache. This way its only built once
# then upload to github. Then download for each as a cache. This way its only built once

# TODO: Add reusable job template here, just changing the `make` command for each

Expand Down Expand Up @@ -186,7 +186,6 @@ jobs:
env:
BRANCH_CI: ${{needs.build-and-push-image.outputs.branchTag}}


# === UNITY CONTRACT ===
test-juno-unity-deploy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -237,4 +236,4 @@ jobs:

- run: make ictest-pfm
env:
BRANCH_CI: ${{needs.build-and-push-image.outputs.branchTag}}
BRANCH_CI: ${{needs.build-and-push-image.outputs.branchTag}}
72 changes: 72 additions & 0 deletions app/upgrades/v16/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package v15

import (
"github.com/CosmosContracts/juno/v16/app/keepers"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Undelegates all tokens, and send it back to the core1 subdao address for the vesting contract to instantiate
func MoveVestingCoinFromVestingAccount(ctx sdk.Context, accAddr sdk.AccAddress, keepers *keepers.AppKeepers, core1SubDaoAddress string) sdk.Coin {
bondDenom := keepers.StakingKeeper.BondDenom(ctx)

now := ctx.BlockHeader().Time

// Complete any active re-delegations
for _, activeRedelegation := range keepers.StakingKeeper.GetRedelegations(ctx, accAddr, 65535) {
redelegationSrc, _ := sdk.ValAddressFromBech32(activeRedelegation.ValidatorSrcAddress)
redelegationDst, _ := sdk.ValAddressFromBech32(activeRedelegation.ValidatorDstAddress)

// set all entry completionTime to now so we can complete redelegation
for i := range activeRedelegation.Entries {
activeRedelegation.Entries[i].CompletionTime = now
}

keepers.StakingKeeper.SetRedelegation(ctx, activeRedelegation)
_, err := keepers.StakingKeeper.CompleteRedelegation(ctx, accAddr, redelegationSrc, redelegationDst)
if err != nil {
panic(err)
}
}

// Unbond all delegations from the account
for _, delegation := range keepers.StakingKeeper.GetAllDelegatorDelegations(ctx, accAddr) {
validatorValAddr := delegation.GetValidatorAddr()
_, found := keepers.StakingKeeper.GetValidator(ctx, validatorValAddr)
if !found {
continue
}
_, err := keepers.StakingKeeper.Undelegate(ctx, accAddr, validatorValAddr, delegation.GetShares())
if err != nil {
panic(err)
}
}

// Complete all delegator's unbonding delegations
for _, unbondingDelegation := range keepers.StakingKeeper.GetAllUnbondingDelegations(ctx, accAddr) {
validatorStringAddr := unbondingDelegation.ValidatorAddress
validatorValAddr, _ := sdk.ValAddressFromBech32(validatorStringAddr)

// Complete unbonding delegation
for i := range unbondingDelegation.Entries {
unbondingDelegation.Entries[i].CompletionTime = now
}
keepers.StakingKeeper.SetUnbondingDelegation(ctx, unbondingDelegation)
_, err := keepers.StakingKeeper.CompleteUnbonding(ctx, accAddr, validatorValAddr)
if err != nil {
panic(err)
}
}

// account balance after finishing unbonding
accCoin := keepers.BankKeeper.GetBalance(ctx, accAddr, bondDenom)

// Send coin to Core-1 subDao for holding on behalf of the core-1 members (interim step)
destAcc, _ := sdk.AccAddressFromBech32(core1SubDaoAddress)
err := keepers.BankKeeper.SendCoins(ctx, accAddr, destAcc, sdk.NewCoins(accCoin))
if err != nil {
panic(err)
}

ctx.Logger().Info("MoveVestingCoinFromVestingAccount", "account", accAddr.String(), "amount", accCoin)
return accCoin
}
103 changes: 103 additions & 0 deletions app/upgrades/v16/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v15

import (
"fmt"
"time"

"github.com/CosmosContracts/juno/v16/app/keepers"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -148,6 +149,108 @@ func CreateV16UpgradeHandler(
return nil, err
}

// Migrate Core-1 vesting accounts
if ctx.ChainID() == "juno-1" {
migrateCore1VestingAccountsToVestingContract(ctx, keepers)
}

return versionMap, err
}
}

func migrateCore1VestingAccountsToVestingContract(ctx sdk.Context, keepers *keepers.AppKeepers) {
// TODO: Easier solution - return all funds back to core1SubDao, then propose new vesting contracts from there.
// Can print out values here for each account on the nodes to ensure each gets what they need + remove the accounts & upgrade time

// https://github.com/DA0-DA0/dao-contracts/tree/main/contracts/external/cw-vesting

// This uses the same CodeId as Reece, Noah, and Ekez's vesting contracts are on for core-1
// https://indexer.daodao.zone/juno-1/contract/juno1axkh35fx7vdtga3s3tj6hadzwdkq8meeq3gen5sardn69lgnmxgslauw4p/cwPayrollFactory/listVestingContracts?
// junod q wasm contract juno1d232p6f2rn4s66j5mp8fqt8h00rh2z6g84vs4ww58zgtulm2fheqs3u3c4 --output json | jq -r .contract_info.code_id

vestingCodeID := 2453
junoUnbondingSeconds := 2419200
core1SubDaoAddr := "juno1j6glql3xmrcnga0gytecsucq3kd88jexxamxg3yn2xnqhunyvflqr7lxx3"

vestingAccounts := map[string]string{
"juno1a...": "Dimi",
"juno1b...": "JackZ",
"juno1c...": "JakeH",
"juno1d...": "Wolf",
"juno1e...": "Block",
// max & alex?
}

// CurrentTime. Used for label in seconds
currentUnixSeconds := getBlockTime(ctx)

// End Vesting Time (Juno Network launch Oct 1st, 2021. Vested 12 years = 2033)
endVestingEpochDate := time.Date(2033, 10, 1, 0, 0, 0, 0, time.UTC)
endVestingEpochSeconds := uint64(endVestingEpochDate.Unix())
vestingDurationSeconds := endVestingEpochSeconds - currentUnixSeconds

// iterate through accounts
// Instantiate on behalf of the core-1 subDAO as the owner, and move all balance, pending rewards, and staked amounts into the new contract
for address, memberName := range vestingAccounts {
fmt.Println(address, memberName)

addr, err := sdk.AccAddressFromBech32(address)
if err != nil {
panic(err)
}

acc := keepers.AccountKeeper.GetAccount(ctx, addr)
if acc == nil {
panic("account not found")
}
// ensure this is a vesting account.

// Does this work for vesting accounts as well under the hood?
preVestedCoin := MoveVestingCoinFromVestingAccount(ctx, addr, keepers, core1SubDaoAddr)
fmt.Printf("moved %d ujuno from %s to %s\n", preVestedCoin.Amount.Int64(), address, core1SubDaoAddr)

// delete the old vesting base account
keepers.AccountKeeper.RemoveAccount(ctx, acc)

// Now funds are in Core-1 Subdao Control, and we can instantiate a vesting contract on behalf of the subdao for the amount stated

// start_time is NOT set as it is Optional. Sets when it is instantiated in nano seconds.
msg := fmt.Sprintf(`{"owner":"%s","recipient":"%s","title":"%s","description":"Core-1 Vesting","total":%d,"denom":{"native":"ujuno"}},"schedule":"saturating_linear","unbonding_duration_seconds":%d,"vesting_duration_seconds":%d}`,
core1SubDaoAddr,
address,
memberName,
preVestedCoin.Amount.Int64(),
junoUnbondingSeconds,
vestingDurationSeconds,
)

// set as label vest_to_juno1addr_1682213004408 where the ending is the current epoch time of prev block
// also pass through funds which must == total.

coins := []sdk.Coin{
sdk.NewCoin("ujuno", sdk.NewInt(preVestedCoin.Amount.Int64())),
}

// use wasmtypes.ContractOpsKeeper here instead of permissioned keeper? or does it matter since we are permissionless anyways
contractAddr, _, err := keepers.ContractKeeper.Instantiate(
ctx,
uint64(vestingCodeID),
sdk.MustAccAddressFromBech32(core1SubDaoAddr),
sdk.MustAccAddressFromBech32(core1SubDaoAddr),
[]byte(msg),
fmt.Sprintf("vest_to_%s_%d", address, currentUnixSeconds),
coins,
)
fmt.Println("Contract Created for:", contractAddr, address, memberName, "With ujuno Amount:", preVestedCoin.Amount.Int64())
if err != nil {
panic(err)
}

}
}

func getBlockTime(ctx sdk.Context) uint64 {
now := ctx.BlockHeader().Time
// get the block time in seconds
return uint64(now.Unix())
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ require (
replace (
// cosmos keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0

// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
// TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
Expand Down
1 change: 1 addition & 0 deletions interchaintest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJ
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
Expand Down
5 changes: 5 additions & 0 deletions proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ deps:
owner: cosmos
repository: cosmos-proto
commit: 1935555c206d4afb9e94615dfd0fad31
digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: 954f7b05f38440fc8250134b15adec47
digest: shake256:2ab4404fd04a7d1d52df0e2d0f2d477a3d83ffd88d876957bf3fedfd702c8e52833d65b3ce1d89a3c5adf2aab512616b0e4f51d8463f07eda9a8a3317ee3ac54
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: 34d970b699f84aa382f3c29773a60836
digest: shake256:3d3bee5229ba579e7d19ffe6e140986a228b48a8c7fe74348f308537ab95e9135210e81812489d42cd8941d33ff71f11583174ccc5972e86e6112924b6ce9f04
- remote: buf.build
owner: cosmos
repository: ics23
commit: 55085f7c710a45f58fa09947208eb70b
digest: shake256:9bf0bc495b5a11c88d163d39ef521bc4b00bc1374a05758c91d82821bdc61f09e8c2c51dda8452529bf80137f34d852561eacbe9550a59015d51cecb0dacb628
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 8d7204855ec14631a499bd7393ce1970
digest: shake256:40bf4112960cad01281930beed85829910768e32e80e986791596853eccd42c0cbd9d96690b918f658020d2d427e16f8b6514e2ac7f4a10306fd32e77be44329