mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 03:55:19 +00:00
remove module's legacy code
This commit is contained in:
parent
625f5e3c13
commit
481dec4d5c
@ -1,57 +0,0 @@
|
||||
package v0_16
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/0glabs/0g-chain/x/bep3/types"
|
||||
)
|
||||
|
||||
// resetSwapForZeroHeight updates swap expiry/close heights to work when the chain height is reset to zero.
|
||||
func resetSwapForZeroHeight(swap types.AtomicSwap) types.AtomicSwap {
|
||||
switch status := swap.Status; status {
|
||||
case types.SWAP_STATUS_COMPLETED:
|
||||
// Reset closed block to one so completed swaps are not held in long term storage too long.
|
||||
swap.ClosedBlock = 1
|
||||
case types.SWAP_STATUS_OPEN:
|
||||
switch dir := swap.Direction; dir {
|
||||
case types.SWAP_DIRECTION_INCOMING:
|
||||
// Open incoming swaps can be expired safely. They haven't been claimed yet, so the outgoing swap on bnb will just timeout.
|
||||
// The chain downtime cannot be accurately predicted, so it's easier to expire than to recalculate a correct expire height.
|
||||
swap.ExpireHeight = 1
|
||||
swap.Status = types.SWAP_STATUS_EXPIRED
|
||||
case types.SWAP_DIRECTION_OUTGOING:
|
||||
// Open outgoing swaps should be extended to allow enough time to claim after the chain launches.
|
||||
// They cannot be expired as there could be an open/claimed bnb swap.
|
||||
swap.ExpireHeight = 1 + 24686 // default timeout used when sending swaps from 0g
|
||||
case types.SWAP_DIRECTION_UNSPECIFIED:
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown bep3 swap direction '%s'", dir))
|
||||
}
|
||||
case types.SWAP_STATUS_EXPIRED:
|
||||
// Once a swap is marked expired the expire height is ignored. However reset to 1 to be sure.
|
||||
swap.ExpireHeight = 1
|
||||
case types.SWAP_STATUS_UNSPECIFIED:
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown bep3 swap status '%s'", status))
|
||||
}
|
||||
|
||||
return swap
|
||||
}
|
||||
|
||||
func resetSwapsForZeroHeight(oldSwaps types.AtomicSwaps) types.AtomicSwaps {
|
||||
newSwaps := make(types.AtomicSwaps, len(oldSwaps))
|
||||
for i, oldSwap := range oldSwaps {
|
||||
swap := resetSwapForZeroHeight(oldSwap)
|
||||
newSwaps[i] = swap
|
||||
}
|
||||
return newSwaps
|
||||
}
|
||||
|
||||
func Migrate(oldState types.GenesisState) *types.GenesisState {
|
||||
return &types.GenesisState{
|
||||
PreviousBlockTime: oldState.PreviousBlockTime,
|
||||
Params: oldState.Params,
|
||||
AtomicSwaps: resetSwapsForZeroHeight(oldState.AtomicSwaps),
|
||||
Supplies: oldState.Supplies,
|
||||
}
|
||||
}
|
@ -1,176 +0,0 @@
|
||||
package v0_16
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
|
||||
app "github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/bep3/types"
|
||||
)
|
||||
|
||||
type migrateTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
addresses []sdk.AccAddress
|
||||
v16genstate types.GenesisState
|
||||
cdc codec.Codec
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) SetupTest() {
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
s.v16genstate = types.GenesisState{
|
||||
PreviousBlockTime: time.Date(2021, 4, 8, 15, 0, 0, 0, time.UTC),
|
||||
Params: types.Params{},
|
||||
Supplies: types.AssetSupplies{},
|
||||
AtomicSwaps: types.AtomicSwaps{},
|
||||
}
|
||||
|
||||
config := app.MakeEncodingConfig()
|
||||
s.cdc = config.Marshaler
|
||||
|
||||
_, accAddresses := app.GeneratePrivKeyAddressPairs(10)
|
||||
s.addresses = accAddresses
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) TestMigrate_JSON() {
|
||||
// Migrate v16 bep3 to v17
|
||||
file := filepath.Join("testdata", "v16-bep3.json")
|
||||
data, err := ioutil.ReadFile(file)
|
||||
s.Require().NoError(err)
|
||||
err = s.cdc.UnmarshalJSON(data, &s.v16genstate)
|
||||
s.Require().NoError(err)
|
||||
genstate := Migrate(s.v16genstate)
|
||||
|
||||
// Compare expect v16 bep3 json with migrated json
|
||||
actual := s.cdc.MustMarshalJSON(genstate)
|
||||
file = filepath.Join("testdata", "v17-bep3.json")
|
||||
expected, err := ioutil.ReadFile(file)
|
||||
s.Require().NoError(err)
|
||||
s.Require().JSONEq(string(expected), string(actual))
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) TestMigrate_Swaps() {
|
||||
type swap struct {
|
||||
ExpireHeight uint64
|
||||
CloseBlock int64
|
||||
Status types.SwapStatus
|
||||
Direction types.SwapDirection
|
||||
}
|
||||
testcases := []struct {
|
||||
name string
|
||||
oldSwap swap
|
||||
newSwap swap
|
||||
}{
|
||||
{
|
||||
name: "incoming open swap",
|
||||
oldSwap: swap{
|
||||
// expire and close not set in open swaps
|
||||
Status: types.SWAP_STATUS_OPEN,
|
||||
Direction: types.SWAP_DIRECTION_INCOMING,
|
||||
},
|
||||
newSwap: swap{
|
||||
ExpireHeight: 1,
|
||||
Status: types.SWAP_STATUS_EXPIRED,
|
||||
Direction: types.SWAP_DIRECTION_INCOMING,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "outgoing open swap",
|
||||
oldSwap: swap{
|
||||
// expire and close not set in open swaps
|
||||
Status: types.SWAP_STATUS_OPEN,
|
||||
Direction: types.SWAP_DIRECTION_OUTGOING,
|
||||
},
|
||||
newSwap: swap{
|
||||
ExpireHeight: 24687,
|
||||
Status: types.SWAP_STATUS_OPEN,
|
||||
Direction: types.SWAP_DIRECTION_OUTGOING,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "completed swap",
|
||||
oldSwap: swap{
|
||||
ExpireHeight: 1000,
|
||||
CloseBlock: 900,
|
||||
Status: types.SWAP_STATUS_COMPLETED,
|
||||
Direction: types.SWAP_DIRECTION_INCOMING,
|
||||
},
|
||||
newSwap: swap{
|
||||
ExpireHeight: 1000,
|
||||
CloseBlock: 1,
|
||||
Status: types.SWAP_STATUS_COMPLETED,
|
||||
Direction: types.SWAP_DIRECTION_INCOMING,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "expired swap",
|
||||
oldSwap: swap{
|
||||
ExpireHeight: 1000,
|
||||
CloseBlock: 900,
|
||||
Status: types.SWAP_STATUS_EXPIRED,
|
||||
Direction: types.SWAP_DIRECTION_INCOMING,
|
||||
},
|
||||
newSwap: swap{
|
||||
ExpireHeight: 1,
|
||||
CloseBlock: 900,
|
||||
Status: types.SWAP_STATUS_EXPIRED,
|
||||
Direction: types.SWAP_DIRECTION_INCOMING,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
s.Run(tc.name, func() {
|
||||
oldSwaps := types.AtomicSwaps{
|
||||
{
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("bnb", sdkmath.NewInt(12))),
|
||||
RandomNumberHash: bytes.HexBytes{},
|
||||
ExpireHeight: tc.oldSwap.ExpireHeight,
|
||||
Timestamp: 1110,
|
||||
Sender: s.addresses[0],
|
||||
Recipient: s.addresses[1],
|
||||
RecipientOtherChain: s.addresses[0].String(),
|
||||
SenderOtherChain: s.addresses[1].String(),
|
||||
ClosedBlock: tc.oldSwap.CloseBlock,
|
||||
Status: tc.oldSwap.Status,
|
||||
CrossChain: true,
|
||||
Direction: tc.oldSwap.Direction,
|
||||
},
|
||||
}
|
||||
expectedSwaps := types.AtomicSwaps{
|
||||
{
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("bnb", sdkmath.NewInt(12))),
|
||||
RandomNumberHash: bytes.HexBytes{},
|
||||
ExpireHeight: tc.newSwap.ExpireHeight,
|
||||
Timestamp: 1110,
|
||||
Sender: s.addresses[0],
|
||||
Recipient: s.addresses[1],
|
||||
RecipientOtherChain: s.addresses[0].String(),
|
||||
SenderOtherChain: s.addresses[1].String(),
|
||||
ClosedBlock: tc.newSwap.CloseBlock,
|
||||
Status: tc.newSwap.Status,
|
||||
CrossChain: true,
|
||||
Direction: tc.newSwap.Direction,
|
||||
},
|
||||
}
|
||||
s.v16genstate.AtomicSwaps = oldSwaps
|
||||
genState := Migrate(s.v16genstate)
|
||||
s.Require().Len(genState.AtomicSwaps, 1)
|
||||
s.Equal(expectedSwaps, genState.AtomicSwaps)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(migrateTestSuite))
|
||||
}
|
212
x/bep3/legacy/v0_17/testdata/v16-bep3.json
vendored
212
x/bep3/legacy/v0_17/testdata/v16-bep3.json
vendored
@ -1,212 +0,0 @@
|
||||
{
|
||||
"atomic_swaps": [
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "1999955998",
|
||||
"denom": "btcb"
|
||||
}
|
||||
],
|
||||
"closed_block": "838115",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_INCOMING",
|
||||
"expire_height": "838627",
|
||||
"random_number_hash": "6F1CF8F2E13A0C0F0A359F54E47E4E265D766B8E006D2F00BDF994ABDEF1E9E4",
|
||||
"recipient": "kava1fl2hs6y9vz986g5v52pdan9ga923n9mn5cxxkw",
|
||||
"recipient_other_chain": "bnb1xz3xqf4p2ygrw9lhp5g5df4ep4nd20vsywnmpr",
|
||||
"sender": "kava14qsmvzprqvhwmgql9fr0u3zv9n2qla8zhnm5pc",
|
||||
"sender_other_chain": "bnb19k9wuv2j7c7ck8tmc7kav0r0cnt3esmkrpf25x",
|
||||
"status": "SWAP_STATUS_COMPLETED",
|
||||
"timestamp": "1636034914"
|
||||
},
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "19000000000",
|
||||
"denom": "bnb"
|
||||
}
|
||||
],
|
||||
"closed_block": "1712118",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_OUTGOING",
|
||||
"expire_height": "1736797",
|
||||
"random_number_hash": "280EB832A37F2265CC82F3957CE603AAD57BAD7038B876A1F28953AFA29FA1C3",
|
||||
"recipient": "kava1r4v2zdhdalfj2ydazallqvrus9fkphmglhn6u6",
|
||||
"recipient_other_chain": "bnb18nsgj50zvc4uq93w4j0ltz5gaxhwv7aq4qnq0p",
|
||||
"sender": "kava1zw6gg4ztvly7zf25pa33mclav3spvj3ympxxna",
|
||||
"sender_other_chain": "bnb1jh7uv2rm6339yue8k4mj9406k3509kr4wt5nxn",
|
||||
"status": "SWAP_STATUS_COMPLETED",
|
||||
"timestamp": "1641976566"
|
||||
},
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "999595462080",
|
||||
"denom": "busd"
|
||||
}
|
||||
],
|
||||
"closed_block": "787122",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_INCOMING",
|
||||
"expire_height": "811799",
|
||||
"random_number_hash": "BFB7CC82DA0E0C8556AC37843F5AB136B9A7A066054368F5948944282B414D83",
|
||||
"recipient": "kava1eufgf0w9d7hf5mgtek4zr2upkxag9stmzx6unl",
|
||||
"recipient_other_chain": "bnb10zq89008gmedc6rrwzdfukjk94swynd7dl97w8",
|
||||
"sender": "kava1hh4x3a4suu5zyaeauvmv7ypf7w9llwlfufjmuu",
|
||||
"sender_other_chain": "bnb1vl3wn4x8kqajg2j9wxa5y5amgzdxchutkxr6at",
|
||||
"status": "SWAP_STATUS_EXPIRED",
|
||||
"timestamp": "1635694492"
|
||||
},
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "999595462080",
|
||||
"denom": "busd"
|
||||
}
|
||||
],
|
||||
"closed_block": "787122",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_OUTGOING",
|
||||
"expire_height": "811799",
|
||||
"random_number_hash": "BFB7CC82DA0E0C8556AC37843F5AB136B9A7A066054368F5948944282B414D83",
|
||||
"recipient": "kava1hh4x3a4suu5zyaeauvmv7ypf7w9llwlfufjmuu",
|
||||
"recipient_other_chain": "bnb1vl3wn4x8kqajg2j9wxa5y5amgzdxchutkxr6at",
|
||||
"sender": "kava1eufgf0w9d7hf5mgtek4zr2upkxag9stmzx6unl",
|
||||
"sender_other_chain": "bnb10zq89008gmedc6rrwzdfukjk94swynd7dl97w8",
|
||||
"status": "SWAP_STATUS_EXPIRED",
|
||||
"timestamp": "1635694492"
|
||||
},
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "1000000",
|
||||
"denom": "btcb"
|
||||
}
|
||||
],
|
||||
"closed_block": "0",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_OUTGOING",
|
||||
"expire_height": "1730589",
|
||||
"random_number_hash": "A74EA1AB58D312FDF1E872D18583CACCF294E639DDA4F303939E9ADCEC081D93",
|
||||
"recipient": "kava14qsmvzprqvhwmgql9fr0u3zv9n2qla8zhnm5pc",
|
||||
"recipient_other_chain": "bnb1lhk5ndlgf5wz55t8k35cqj6h9l3m4l5ek2w7q6",
|
||||
"sender": "kava1d2u28azje7rhqyjtxc2ex8q0cxxpw7dfm7ltq5",
|
||||
"sender_other_chain": "bnb1xz3xqf4p2ygrw9lhp5g5df4ep4nd20vsywnmpr",
|
||||
"status": "SWAP_STATUS_OPEN",
|
||||
"timestamp": "1641934114"
|
||||
},
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "1000000",
|
||||
"denom": "btcb"
|
||||
}
|
||||
],
|
||||
"closed_block": "0",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_INCOMING",
|
||||
"expire_height": "1740000",
|
||||
"random_number_hash": "39E9ADCEC081D93A74EA1A83CACCF294E639DDA4F3039B58D312FDF1E872D185",
|
||||
"recipient": "kava1d2u28azje7rhqyjtxc2ex8q0cxxpw7dfm7ltq5",
|
||||
"recipient_other_chain": "bnb1xz3xqf4p2ygrw9lhp5g5df4ep4nd20vsywnmpr",
|
||||
"sender": "kava14qsmvzprqvhwmgql9fr0u3zv9n2qla8zhnm5pc",
|
||||
"sender_other_chain": "bnb1lhk5ndlgf5wz55t8k35cqj6h9l3m4l5ek2w7q6",
|
||||
"status": "SWAP_STATUS_OPEN",
|
||||
"timestamp": "1641934114"
|
||||
}
|
||||
],
|
||||
"params": {
|
||||
"asset_params": [
|
||||
{
|
||||
"active": true,
|
||||
"coin_id": "0",
|
||||
"denom": "btcb",
|
||||
"deputy_address": "kava1kla4wl0ccv7u85cemvs3y987hqk0afcv7vue84",
|
||||
"fixed_fee": "2",
|
||||
"max_block_lock": "86400",
|
||||
"max_swap_amount": "2000000000",
|
||||
"min_block_lock": "24686",
|
||||
"min_swap_amount": "3",
|
||||
"supply_limit": {
|
||||
"limit": "100000000000",
|
||||
"time_based_limit": "0",
|
||||
"time_limited": false,
|
||||
"time_period": "0s"
|
||||
}
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"coin_id": "144",
|
||||
"denom": "xrpb",
|
||||
"deputy_address": "kava14q5sawxdxtpap5x5sgzj7v4sp3ucncjlpuk3hs",
|
||||
"fixed_fee": "100000",
|
||||
"max_block_lock": "86400",
|
||||
"max_swap_amount": "250000000000000",
|
||||
"min_block_lock": "24686",
|
||||
"min_swap_amount": "100001",
|
||||
"supply_limit": {
|
||||
"limit": "2000000000000000",
|
||||
"time_based_limit": "0",
|
||||
"time_limited": false,
|
||||
"time_period": "0s"
|
||||
}
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"coin_id": "714",
|
||||
"denom": "bnb",
|
||||
"deputy_address": "kava1agcvt07tcw0tglu0hmwdecsnuxp2yd45f3avgm",
|
||||
"fixed_fee": "1000",
|
||||
"max_block_lock": "86400",
|
||||
"max_swap_amount": "500000000000",
|
||||
"min_block_lock": "24686",
|
||||
"min_swap_amount": "1001",
|
||||
"supply_limit": {
|
||||
"limit": "100000000000000",
|
||||
"time_based_limit": "0",
|
||||
"time_limited": false,
|
||||
"time_period": "0s"
|
||||
}
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"coin_id": "727",
|
||||
"denom": "busd",
|
||||
"deputy_address": "kava1j9je7f6s0v6k7dmgv6u5k5ru202f5ffsc7af04",
|
||||
"fixed_fee": "20000",
|
||||
"max_block_lock": "86400",
|
||||
"max_swap_amount": "100000000000000",
|
||||
"min_block_lock": "24686",
|
||||
"min_swap_amount": "20001",
|
||||
"supply_limit": {
|
||||
"limit": "2000000000000000",
|
||||
"time_based_limit": "0",
|
||||
"time_limited": false,
|
||||
"time_period": "0s"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"previous_block_time": "1970-01-01T00:00:00Z",
|
||||
"supplies": [
|
||||
{
|
||||
"current_supply": {
|
||||
"amount": "30467559434006",
|
||||
"denom": "bnb"
|
||||
},
|
||||
"incoming_supply": {
|
||||
"amount": "0",
|
||||
"denom": "bnb"
|
||||
},
|
||||
"outgoing_supply": {
|
||||
"amount": "0",
|
||||
"denom": "bnb"
|
||||
},
|
||||
"time_elapsed": "0s",
|
||||
"time_limited_current_supply": {
|
||||
"amount": "0",
|
||||
"denom": "bnb"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
212
x/bep3/legacy/v0_17/testdata/v17-bep3.json
vendored
212
x/bep3/legacy/v0_17/testdata/v17-bep3.json
vendored
@ -1,212 +0,0 @@
|
||||
{
|
||||
"atomic_swaps": [
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "1999955998",
|
||||
"denom": "btcb"
|
||||
}
|
||||
],
|
||||
"closed_block": "1",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_INCOMING",
|
||||
"expire_height": "838627",
|
||||
"random_number_hash": "6F1CF8F2E13A0C0F0A359F54E47E4E265D766B8E006D2F00BDF994ABDEF1E9E4",
|
||||
"recipient": "kava1fl2hs6y9vz986g5v52pdan9ga923n9mn5cxxkw",
|
||||
"recipient_other_chain": "bnb1xz3xqf4p2ygrw9lhp5g5df4ep4nd20vsywnmpr",
|
||||
"sender": "kava14qsmvzprqvhwmgql9fr0u3zv9n2qla8zhnm5pc",
|
||||
"sender_other_chain": "bnb19k9wuv2j7c7ck8tmc7kav0r0cnt3esmkrpf25x",
|
||||
"status": "SWAP_STATUS_COMPLETED",
|
||||
"timestamp": "1636034914"
|
||||
},
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "19000000000",
|
||||
"denom": "bnb"
|
||||
}
|
||||
],
|
||||
"closed_block": "1",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_OUTGOING",
|
||||
"expire_height": "1736797",
|
||||
"random_number_hash": "280EB832A37F2265CC82F3957CE603AAD57BAD7038B876A1F28953AFA29FA1C3",
|
||||
"recipient": "kava1r4v2zdhdalfj2ydazallqvrus9fkphmglhn6u6",
|
||||
"recipient_other_chain": "bnb18nsgj50zvc4uq93w4j0ltz5gaxhwv7aq4qnq0p",
|
||||
"sender": "kava1zw6gg4ztvly7zf25pa33mclav3spvj3ympxxna",
|
||||
"sender_other_chain": "bnb1jh7uv2rm6339yue8k4mj9406k3509kr4wt5nxn",
|
||||
"status": "SWAP_STATUS_COMPLETED",
|
||||
"timestamp": "1641976566"
|
||||
},
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "999595462080",
|
||||
"denom": "busd"
|
||||
}
|
||||
],
|
||||
"closed_block": "787122",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_INCOMING",
|
||||
"expire_height": "1",
|
||||
"random_number_hash": "BFB7CC82DA0E0C8556AC37843F5AB136B9A7A066054368F5948944282B414D83",
|
||||
"recipient": "kava1eufgf0w9d7hf5mgtek4zr2upkxag9stmzx6unl",
|
||||
"recipient_other_chain": "bnb10zq89008gmedc6rrwzdfukjk94swynd7dl97w8",
|
||||
"sender": "kava1hh4x3a4suu5zyaeauvmv7ypf7w9llwlfufjmuu",
|
||||
"sender_other_chain": "bnb1vl3wn4x8kqajg2j9wxa5y5amgzdxchutkxr6at",
|
||||
"status": "SWAP_STATUS_EXPIRED",
|
||||
"timestamp": "1635694492"
|
||||
},
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "999595462080",
|
||||
"denom": "busd"
|
||||
}
|
||||
],
|
||||
"closed_block": "787122",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_OUTGOING",
|
||||
"expire_height": "1",
|
||||
"random_number_hash": "BFB7CC82DA0E0C8556AC37843F5AB136B9A7A066054368F5948944282B414D83",
|
||||
"recipient": "kava1hh4x3a4suu5zyaeauvmv7ypf7w9llwlfufjmuu",
|
||||
"recipient_other_chain": "bnb1vl3wn4x8kqajg2j9wxa5y5amgzdxchutkxr6at",
|
||||
"sender": "kava1eufgf0w9d7hf5mgtek4zr2upkxag9stmzx6unl",
|
||||
"sender_other_chain": "bnb10zq89008gmedc6rrwzdfukjk94swynd7dl97w8",
|
||||
"status": "SWAP_STATUS_EXPIRED",
|
||||
"timestamp": "1635694492"
|
||||
},
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "1000000",
|
||||
"denom": "btcb"
|
||||
}
|
||||
],
|
||||
"closed_block": "0",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_OUTGOING",
|
||||
"expire_height": "24687",
|
||||
"random_number_hash": "A74EA1AB58D312FDF1E872D18583CACCF294E639DDA4F303939E9ADCEC081D93",
|
||||
"recipient": "kava14qsmvzprqvhwmgql9fr0u3zv9n2qla8zhnm5pc",
|
||||
"recipient_other_chain": "bnb1lhk5ndlgf5wz55t8k35cqj6h9l3m4l5ek2w7q6",
|
||||
"sender": "kava1d2u28azje7rhqyjtxc2ex8q0cxxpw7dfm7ltq5",
|
||||
"sender_other_chain": "bnb1xz3xqf4p2ygrw9lhp5g5df4ep4nd20vsywnmpr",
|
||||
"status": "SWAP_STATUS_OPEN",
|
||||
"timestamp": "1641934114"
|
||||
},
|
||||
{
|
||||
"amount": [
|
||||
{
|
||||
"amount": "1000000",
|
||||
"denom": "btcb"
|
||||
}
|
||||
],
|
||||
"closed_block": "0",
|
||||
"cross_chain": true,
|
||||
"direction": "SWAP_DIRECTION_INCOMING",
|
||||
"expire_height": "1",
|
||||
"random_number_hash": "39E9ADCEC081D93A74EA1A83CACCF294E639DDA4F3039B58D312FDF1E872D185",
|
||||
"recipient": "kava1d2u28azje7rhqyjtxc2ex8q0cxxpw7dfm7ltq5",
|
||||
"recipient_other_chain": "bnb1xz3xqf4p2ygrw9lhp5g5df4ep4nd20vsywnmpr",
|
||||
"sender": "kava14qsmvzprqvhwmgql9fr0u3zv9n2qla8zhnm5pc",
|
||||
"sender_other_chain": "bnb1lhk5ndlgf5wz55t8k35cqj6h9l3m4l5ek2w7q6",
|
||||
"status": "SWAP_STATUS_EXPIRED",
|
||||
"timestamp": "1641934114"
|
||||
}
|
||||
],
|
||||
"params": {
|
||||
"asset_params": [
|
||||
{
|
||||
"active": true,
|
||||
"coin_id": "0",
|
||||
"denom": "btcb",
|
||||
"deputy_address": "kava1kla4wl0ccv7u85cemvs3y987hqk0afcv7vue84",
|
||||
"fixed_fee": "2",
|
||||
"max_block_lock": "86400",
|
||||
"max_swap_amount": "2000000000",
|
||||
"min_block_lock": "24686",
|
||||
"min_swap_amount": "3",
|
||||
"supply_limit": {
|
||||
"limit": "100000000000",
|
||||
"time_based_limit": "0",
|
||||
"time_limited": false,
|
||||
"time_period": "0s"
|
||||
}
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"coin_id": "144",
|
||||
"denom": "xrpb",
|
||||
"deputy_address": "kava14q5sawxdxtpap5x5sgzj7v4sp3ucncjlpuk3hs",
|
||||
"fixed_fee": "100000",
|
||||
"max_block_lock": "86400",
|
||||
"max_swap_amount": "250000000000000",
|
||||
"min_block_lock": "24686",
|
||||
"min_swap_amount": "100001",
|
||||
"supply_limit": {
|
||||
"limit": "2000000000000000",
|
||||
"time_based_limit": "0",
|
||||
"time_limited": false,
|
||||
"time_period": "0s"
|
||||
}
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"coin_id": "714",
|
||||
"denom": "bnb",
|
||||
"deputy_address": "kava1agcvt07tcw0tglu0hmwdecsnuxp2yd45f3avgm",
|
||||
"fixed_fee": "1000",
|
||||
"max_block_lock": "86400",
|
||||
"max_swap_amount": "500000000000",
|
||||
"min_block_lock": "24686",
|
||||
"min_swap_amount": "1001",
|
||||
"supply_limit": {
|
||||
"limit": "100000000000000",
|
||||
"time_based_limit": "0",
|
||||
"time_limited": false,
|
||||
"time_period": "0s"
|
||||
}
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"coin_id": "727",
|
||||
"denom": "busd",
|
||||
"deputy_address": "kava1j9je7f6s0v6k7dmgv6u5k5ru202f5ffsc7af04",
|
||||
"fixed_fee": "20000",
|
||||
"max_block_lock": "86400",
|
||||
"max_swap_amount": "100000000000000",
|
||||
"min_block_lock": "24686",
|
||||
"min_swap_amount": "20001",
|
||||
"supply_limit": {
|
||||
"limit": "2000000000000000",
|
||||
"time_based_limit": "0",
|
||||
"time_limited": false,
|
||||
"time_period": "0s"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"previous_block_time": "1970-01-01T00:00:00Z",
|
||||
"supplies": [
|
||||
{
|
||||
"current_supply": {
|
||||
"amount": "30467559434006",
|
||||
"denom": "bnb"
|
||||
},
|
||||
"incoming_supply": {
|
||||
"amount": "0",
|
||||
"denom": "bnb"
|
||||
},
|
||||
"outgoing_supply": {
|
||||
"amount": "0",
|
||||
"denom": "bnb"
|
||||
},
|
||||
"time_elapsed": "0s",
|
||||
"time_limited_current_supply": {
|
||||
"amount": "0",
|
||||
"denom": "bnb"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package v0_15
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// ModuleName The name that will be used throughout the module
|
||||
ModuleName = "issuance"
|
||||
)
|
||||
|
||||
// GenesisState is the state that must be provided at genesis for the issuance module
|
||||
type GenesisState struct {
|
||||
Params Params `json:"params" yaml:"params"`
|
||||
Supplies AssetSupplies `json:"supplies" yaml:"supplies"`
|
||||
}
|
||||
|
||||
// Params governance parameters for the issuance module
|
||||
type Params struct {
|
||||
Assets Assets `json:"assets" yaml:"assets"`
|
||||
}
|
||||
|
||||
// Assets slice of Asset
|
||||
type Assets []Asset
|
||||
|
||||
// Asset type for assets in the issuance module
|
||||
type Asset struct {
|
||||
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
BlockedAddresses []sdk.AccAddress `json:"blocked_addresses" yaml:"blocked_addresses"`
|
||||
Paused bool `json:"paused" yaml:"paused"`
|
||||
Blockable bool `json:"blockable" yaml:"blockable"`
|
||||
RateLimit RateLimit `json:"rate_limit" yaml:"rate_limit"`
|
||||
}
|
||||
|
||||
// RateLimit parameters for rate-limiting the supply of an issued asset
|
||||
type RateLimit struct {
|
||||
Active bool `json:"active" yaml:"active"`
|
||||
Limit sdkmath.Int `json:"limit" yaml:"limit"`
|
||||
TimePeriod time.Duration `json:"time_period" yaml:"time_period"`
|
||||
}
|
||||
|
||||
// AssetSupplies is a slice of AssetSupply
|
||||
type AssetSupplies []AssetSupply
|
||||
|
||||
// AssetSupply contains information about an asset's rate-limited supply (the total supply of the asset is tracked in the top-level supply module)
|
||||
type AssetSupply struct {
|
||||
CurrentSupply sdk.Coin `json:"current_supply" yaml:"current_supply"`
|
||||
TimeElapsed time.Duration `json:"time_elapsed" yaml:"time_elapsed"`
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package v0_16
|
||||
|
||||
import (
|
||||
v015issuance "github.com/0glabs/0g-chain/x/issuance/legacy/v0_15"
|
||||
v016issuance "github.com/0glabs/0g-chain/x/issuance/types"
|
||||
)
|
||||
|
||||
func migrateParams(params v015issuance.Params) v016issuance.Params {
|
||||
assets := make([]v016issuance.Asset, len(params.Assets))
|
||||
for i, asset := range params.Assets {
|
||||
blockedAddresses := make([]string, len(asset.BlockedAddresses))
|
||||
for i, addr := range asset.BlockedAddresses {
|
||||
blockedAddresses[i] = addr.String()
|
||||
}
|
||||
assets[i] = v016issuance.Asset{
|
||||
Owner: asset.Owner.String(),
|
||||
Denom: asset.Denom,
|
||||
BlockedAddresses: blockedAddresses,
|
||||
Paused: asset.Paused,
|
||||
Blockable: asset.Blockable,
|
||||
RateLimit: v016issuance.RateLimit{
|
||||
Active: asset.RateLimit.Active,
|
||||
Limit: asset.RateLimit.Limit,
|
||||
TimePeriod: asset.RateLimit.TimePeriod,
|
||||
},
|
||||
}
|
||||
}
|
||||
return v016issuance.Params{Assets: assets}
|
||||
}
|
||||
|
||||
func migrateSupplies(oldSupplies v015issuance.AssetSupplies) []v016issuance.AssetSupply {
|
||||
supplies := make([]v016issuance.AssetSupply, len(oldSupplies))
|
||||
for i, supply := range oldSupplies {
|
||||
supplies[i] = v016issuance.AssetSupply{
|
||||
CurrentSupply: supply.CurrentSupply,
|
||||
TimeElapsed: supply.TimeElapsed,
|
||||
}
|
||||
}
|
||||
return supplies
|
||||
}
|
||||
|
||||
// Migrate converts v0.15 issuance state and returns it in v0.16 format
|
||||
func Migrate(oldState v015issuance.GenesisState) *v016issuance.GenesisState {
|
||||
return &v016issuance.GenesisState{
|
||||
Params: migrateParams(oldState.Params),
|
||||
Supplies: migrateSupplies(oldState.Supplies),
|
||||
}
|
||||
}
|
@ -1,177 +0,0 @@
|
||||
package v0_16
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
app "github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
v015issuance "github.com/0glabs/0g-chain/x/issuance/legacy/v0_15"
|
||||
v016issuance "github.com/0glabs/0g-chain/x/issuance/types"
|
||||
)
|
||||
|
||||
type migrateTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
addresses []sdk.AccAddress
|
||||
v15genstate v015issuance.GenesisState
|
||||
cdc codec.Codec
|
||||
legacyCdc *codec.LegacyAmino
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) SetupTest() {
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
s.v15genstate = v015issuance.GenesisState{
|
||||
Params: v015issuance.Params{},
|
||||
Supplies: v015issuance.AssetSupplies{},
|
||||
}
|
||||
|
||||
config := app.MakeEncodingConfig()
|
||||
s.cdc = config.Marshaler
|
||||
|
||||
legacyCodec := codec.NewLegacyAmino()
|
||||
s.legacyCdc = legacyCodec
|
||||
|
||||
_, accAddresses := app.GeneratePrivKeyAddressPairs(10)
|
||||
s.addresses = accAddresses
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) TestMigrate_JSON() {
|
||||
// Migrate v15 issuance to v16
|
||||
data := `{
|
||||
"params": {
|
||||
"assets": [
|
||||
{
|
||||
"blockable": true,
|
||||
"blocked_addresses": null,
|
||||
"denom": "hbtc",
|
||||
"owner": "0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8",
|
||||
"paused": false,
|
||||
"rate_limit": {
|
||||
"active": false,
|
||||
"limit": "0",
|
||||
"time_period": "0"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"supplies": [
|
||||
{
|
||||
"current_supply": { "denom": "ua0gi", "amount": "100" },
|
||||
"time_elapsed": "3600000000000"
|
||||
},
|
||||
{
|
||||
"current_supply": { "denom": "bnb", "amount": "300" },
|
||||
"time_elapsed": "300000000000"
|
||||
}
|
||||
]
|
||||
}`
|
||||
err := s.legacyCdc.UnmarshalJSON([]byte(data), &s.v15genstate)
|
||||
s.Require().NoError(err)
|
||||
genstate := Migrate(s.v15genstate)
|
||||
|
||||
// Compare expect v16 issuance json with migrated json
|
||||
expected := `{
|
||||
"params": {
|
||||
"assets": [
|
||||
{
|
||||
"blockable": true,
|
||||
"blocked_addresses": [],
|
||||
"denom": "hbtc",
|
||||
"owner": "0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8",
|
||||
"paused": false,
|
||||
"rate_limit": {
|
||||
"active": false,
|
||||
"limit": "0",
|
||||
"time_period": "0s"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"supplies": [
|
||||
{
|
||||
"current_supply": { "denom": "ua0gi", "amount": "100" },
|
||||
"time_elapsed": "3600s"
|
||||
},
|
||||
{
|
||||
"current_supply": { "denom": "bnb", "amount": "300" },
|
||||
"time_elapsed": "300s"
|
||||
}
|
||||
]
|
||||
}`
|
||||
actual := s.cdc.MustMarshalJSON(genstate)
|
||||
s.Require().NoError(err)
|
||||
s.Require().JSONEq(expected, string(actual))
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) TestMigrate_Params() {
|
||||
s.v15genstate.Params = v015issuance.Params{
|
||||
Assets: v015issuance.Assets{
|
||||
{
|
||||
Owner: s.addresses[0],
|
||||
Denom: "ua0gi",
|
||||
BlockedAddresses: s.addresses[1:2],
|
||||
Paused: true,
|
||||
Blockable: true,
|
||||
RateLimit: v015issuance.RateLimit{
|
||||
Active: true,
|
||||
Limit: sdkmath.NewInt(10),
|
||||
TimePeriod: 1 * time.Hour,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
expectedParams := v016issuance.Params{
|
||||
Assets: []v016issuance.Asset{
|
||||
{
|
||||
Owner: s.addresses[0].String(),
|
||||
Denom: "ua0gi",
|
||||
BlockedAddresses: []string{s.addresses[1].String()},
|
||||
Paused: true,
|
||||
Blockable: true,
|
||||
RateLimit: v016issuance.RateLimit{
|
||||
Active: true,
|
||||
Limit: sdkmath.NewInt(10),
|
||||
TimePeriod: 1 * time.Hour,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
genState := Migrate(s.v15genstate)
|
||||
s.Require().Equal(expectedParams, genState.Params)
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) TestMigrate_Supplies() {
|
||||
s.v15genstate.Supplies = v015issuance.AssetSupplies{
|
||||
{
|
||||
CurrentSupply: sdk.NewCoin("ua0gi", sdkmath.NewInt(100)),
|
||||
TimeElapsed: time.Duration(1 * time.Hour),
|
||||
},
|
||||
{
|
||||
CurrentSupply: sdk.NewCoin("bnb", sdkmath.NewInt(300)),
|
||||
TimeElapsed: time.Duration(5 * time.Minute),
|
||||
},
|
||||
}
|
||||
expected := []v016issuance.AssetSupply{
|
||||
{
|
||||
CurrentSupply: sdk.NewCoin("ua0gi", sdkmath.NewInt(100)),
|
||||
TimeElapsed: time.Duration(1 * time.Hour),
|
||||
},
|
||||
{
|
||||
CurrentSupply: sdk.NewCoin("bnb", sdkmath.NewInt(300)),
|
||||
TimeElapsed: time.Duration(5 * time.Minute),
|
||||
},
|
||||
}
|
||||
genState := Migrate(s.v15genstate)
|
||||
s.Require().Equal(expected, genState.Supplies)
|
||||
}
|
||||
|
||||
func TestIssuanceMigrateTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(migrateTestSuite))
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package v0_15
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// ModuleName The name that will be used throughout the module
|
||||
ModuleName = "pricefeed"
|
||||
)
|
||||
|
||||
// GenesisState - pricefeed state that must be provided at genesis
|
||||
type GenesisState struct {
|
||||
Params Params `json:"params" yaml:"params"`
|
||||
PostedPrices PostedPrices `json:"posted_prices" yaml:"posted_prices"`
|
||||
}
|
||||
|
||||
// Params params for pricefeed. Can be altered via governance
|
||||
type Params struct {
|
||||
Markets Markets `json:"markets" yaml:"markets"` // Array containing the markets supported by the pricefeed
|
||||
}
|
||||
|
||||
// Markets array type for oracle
|
||||
type Markets []Market
|
||||
|
||||
// Market an asset in the pricefeed
|
||||
type Market struct {
|
||||
MarketID string `json:"market_id" yaml:"market_id"`
|
||||
BaseAsset string `json:"base_asset" yaml:"base_asset"`
|
||||
QuoteAsset string `json:"quote_asset" yaml:"quote_asset"`
|
||||
Oracles []sdk.AccAddress `json:"oracles" yaml:"oracles"`
|
||||
Active bool `json:"active" yaml:"active"`
|
||||
}
|
||||
|
||||
// PostedPrices type for an array of PostedPrice
|
||||
type PostedPrices []PostedPrice
|
||||
|
||||
// PostedPrice price for market posted by a specific oracle
|
||||
type PostedPrice struct {
|
||||
MarketID string `json:"market_id" yaml:"market_id"`
|
||||
OracleAddress sdk.AccAddress `json:"oracle_address" yaml:"oracle_address"`
|
||||
Price sdk.Dec `json:"price" yaml:"price"`
|
||||
Expiry time.Time `json:"expiry" yaml:"expiry"`
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
package v0_16
|
||||
|
||||
import (
|
||||
v015pricefeed "github.com/0glabs/0g-chain/x/pricefeed/legacy/v0_15"
|
||||
v016pricefeed "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var NewIBCMarkets = []v016pricefeed.Market{
|
||||
{
|
||||
MarketID: "atom:usd",
|
||||
BaseAsset: "atom",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: nil,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "atom:usd:30",
|
||||
BaseAsset: "atom",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: nil,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "akt:usd",
|
||||
BaseAsset: "akt",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: nil,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "akt:usd:30",
|
||||
BaseAsset: "akt",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: nil,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "luna:usd",
|
||||
BaseAsset: "luna",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: nil,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "luna:usd:30",
|
||||
BaseAsset: "luna",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: nil,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "osmo:usd",
|
||||
BaseAsset: "osmo",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: nil,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "osmo:usd:30",
|
||||
BaseAsset: "osmo",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: nil,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "ust:usd",
|
||||
BaseAsset: "ust",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: nil,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "ust:usd:30",
|
||||
BaseAsset: "ust",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: nil,
|
||||
Active: true,
|
||||
},
|
||||
}
|
||||
|
||||
func migrateParams(params v015pricefeed.Params) v016pricefeed.Params {
|
||||
markets := make(v016pricefeed.Markets, len(params.Markets))
|
||||
for i, market := range params.Markets {
|
||||
markets[i] = v016pricefeed.Market{
|
||||
MarketID: market.MarketID,
|
||||
BaseAsset: market.BaseAsset,
|
||||
QuoteAsset: market.QuoteAsset,
|
||||
Oracles: market.Oracles,
|
||||
Active: market.Active,
|
||||
}
|
||||
}
|
||||
|
||||
markets = addIbcMarkets(markets)
|
||||
|
||||
return v016pricefeed.Params{Markets: markets}
|
||||
}
|
||||
|
||||
func addIbcMarkets(markets v016pricefeed.Markets) v016pricefeed.Markets {
|
||||
var oracles []types.AccAddress
|
||||
|
||||
if len(markets) > 0 {
|
||||
oracles = markets[0].Oracles
|
||||
}
|
||||
|
||||
for _, newMarket := range NewIBCMarkets {
|
||||
// newMarket is a copy, should not affect other uses of NewIBCMarkets
|
||||
newMarket.Oracles = oracles
|
||||
markets = append(markets, newMarket)
|
||||
}
|
||||
|
||||
return markets
|
||||
}
|
||||
|
||||
func migratePostedPrices(oldPostedPrices v015pricefeed.PostedPrices) v016pricefeed.PostedPrices {
|
||||
newPrices := make(v016pricefeed.PostedPrices, len(oldPostedPrices))
|
||||
for i, price := range oldPostedPrices {
|
||||
newPrices[i] = v016pricefeed.PostedPrice{
|
||||
MarketID: price.MarketID,
|
||||
OracleAddress: price.OracleAddress,
|
||||
Price: price.Price,
|
||||
Expiry: price.Expiry,
|
||||
}
|
||||
}
|
||||
return newPrices
|
||||
}
|
||||
|
||||
// Migrate converts v0.15 pricefeed state and returns it in v0.16 format
|
||||
func Migrate(oldState v015pricefeed.GenesisState) *v016pricefeed.GenesisState {
|
||||
return &v016pricefeed.GenesisState{
|
||||
Params: migrateParams(oldState.Params),
|
||||
PostedPrices: migratePostedPrices(oldState.PostedPrices),
|
||||
}
|
||||
}
|
@ -1,353 +0,0 @@
|
||||
package v0_16
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
app "github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
v015pricefeed "github.com/0glabs/0g-chain/x/pricefeed/legacy/v0_15"
|
||||
v016pricefeed "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||
)
|
||||
|
||||
type migrateTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
addresses []sdk.AccAddress
|
||||
v15genstate v015pricefeed.GenesisState
|
||||
cdc codec.Codec
|
||||
legacyCdc *codec.LegacyAmino
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) SetupTest() {
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
s.v15genstate = v015pricefeed.GenesisState{
|
||||
Params: v015pricefeed.Params{},
|
||||
PostedPrices: v015pricefeed.PostedPrices{},
|
||||
}
|
||||
|
||||
config := app.MakeEncodingConfig()
|
||||
s.cdc = config.Marshaler
|
||||
|
||||
legacyCodec := codec.NewLegacyAmino()
|
||||
s.legacyCdc = legacyCodec
|
||||
|
||||
_, accAddresses := app.GeneratePrivKeyAddressPairs(10)
|
||||
s.addresses = accAddresses
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) TestMigrate_JSON() {
|
||||
// Migrate v15 pricefeed to v16
|
||||
v15Params := `{
|
||||
"params": {
|
||||
"markets": [
|
||||
{
|
||||
"active": true,
|
||||
"base_asset": "bnb",
|
||||
"market_id": "bnb:usd",
|
||||
"oracles": ["0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"],
|
||||
"quote_asset": "usd"
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"base_asset": "bnb",
|
||||
"market_id": "bnb:usd:30",
|
||||
"oracles": ["0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"],
|
||||
"quote_asset": "usd"
|
||||
}
|
||||
]
|
||||
},
|
||||
"posted_prices": [
|
||||
{
|
||||
"expiry": "2022-07-20T00:00:00Z",
|
||||
"market_id": "bnb:usd",
|
||||
"oracle_address": "0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8",
|
||||
"price": "215.962650000000001782"
|
||||
},
|
||||
{
|
||||
"expiry": "2022-07-20T00:00:00Z",
|
||||
"market_id": "bnb:usd:30",
|
||||
"oracle_address": "0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8",
|
||||
"price": "217.962650000000001782"
|
||||
}
|
||||
]
|
||||
}`
|
||||
|
||||
expectedV16Params := `{
|
||||
"params": {
|
||||
"markets": [
|
||||
{
|
||||
"market_id": "bnb:usd",
|
||||
"base_asset": "bnb",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"market_id": "bnb:usd:30",
|
||||
"base_asset": "bnb",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"market_id": "atom:usd",
|
||||
"base_asset": "atom",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"market_id": "atom:usd:30",
|
||||
"base_asset": "atom",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"market_id": "akt:usd",
|
||||
"base_asset": "akt",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"market_id": "akt:usd:30",
|
||||
"base_asset": "akt",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"market_id": "luna:usd",
|
||||
"base_asset": "luna",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"market_id": "luna:usd:30",
|
||||
"base_asset": "luna",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"market_id": "osmo:usd",
|
||||
"base_asset": "osmo",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"market_id": "osmo:usd:30",
|
||||
"base_asset": "osmo",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"market_id": "ust:usd",
|
||||
"base_asset": "ust",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"market_id": "ust:usd:30",
|
||||
"base_asset": "ust",
|
||||
"quote_asset": "usd",
|
||||
"oracles": [
|
||||
"0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8"
|
||||
],
|
||||
"active": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"posted_prices": [
|
||||
{
|
||||
"market_id": "bnb:usd",
|
||||
"oracle_address": "0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8",
|
||||
"price": "215.962650000000001782",
|
||||
"expiry": "2022-07-20T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"market_id": "bnb:usd:30",
|
||||
"oracle_address": "0g1ffv7nhd3z6sych2qpqkk03ec6hzkmufyhp5hf8",
|
||||
"price": "217.962650000000001782",
|
||||
"expiry": "2022-07-20T00:00:00Z"
|
||||
}
|
||||
]
|
||||
}`
|
||||
|
||||
err := s.legacyCdc.UnmarshalJSON([]byte(v15Params), &s.v15genstate)
|
||||
s.Require().NoError(err)
|
||||
genstate := Migrate(s.v15genstate)
|
||||
|
||||
// v16 pricefeed json should be the same as v15 but with IBC markets added
|
||||
actual := s.cdc.MustMarshalJSON(genstate)
|
||||
|
||||
s.Require().NoError(err)
|
||||
s.Require().JSONEq(expectedV16Params, string(actual))
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) TestMigrate_Params() {
|
||||
s.v15genstate.Params = v015pricefeed.Params{
|
||||
Markets: v015pricefeed.Markets{
|
||||
{
|
||||
MarketID: "market-1",
|
||||
BaseAsset: "a0gi",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
expectedParams := v016pricefeed.Params{
|
||||
Markets: v016pricefeed.Markets{
|
||||
{
|
||||
MarketID: "market-1",
|
||||
BaseAsset: "a0gi",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "atom:usd",
|
||||
BaseAsset: "atom",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "atom:usd:30",
|
||||
BaseAsset: "atom",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "akt:usd",
|
||||
BaseAsset: "akt",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "akt:usd:30",
|
||||
BaseAsset: "akt",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "luna:usd",
|
||||
BaseAsset: "luna",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "luna:usd:30",
|
||||
BaseAsset: "luna",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "osmo:usd",
|
||||
BaseAsset: "osmo",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "osmo:usd:30",
|
||||
BaseAsset: "osmo",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "ust:usd",
|
||||
BaseAsset: "ust",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "ust:usd:30",
|
||||
BaseAsset: "ust",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: s.addresses,
|
||||
Active: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
genState := Migrate(s.v15genstate)
|
||||
s.Require().Equal(expectedParams, genState.Params)
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) TestMigrate_PostedPrices() {
|
||||
s.v15genstate.PostedPrices = v015pricefeed.PostedPrices{
|
||||
{
|
||||
MarketID: "market-1",
|
||||
OracleAddress: s.addresses[0],
|
||||
Price: sdk.MustNewDecFromStr("1.2"),
|
||||
Expiry: time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
{
|
||||
MarketID: "market-2",
|
||||
OracleAddress: s.addresses[1],
|
||||
Price: sdk.MustNewDecFromStr("1.899"),
|
||||
Expiry: time.Date(2021, time.January, 1, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
expected := v016pricefeed.PostedPrices{
|
||||
{
|
||||
MarketID: "market-1",
|
||||
OracleAddress: s.addresses[0],
|
||||
Price: sdk.MustNewDecFromStr("1.2"),
|
||||
Expiry: time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
{
|
||||
MarketID: "market-2",
|
||||
OracleAddress: s.addresses[1],
|
||||
Price: sdk.MustNewDecFromStr("1.899"),
|
||||
Expiry: time.Date(2021, time.January, 1, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
genState := Migrate(s.v15genstate)
|
||||
s.Require().Equal(expected, genState.PostedPrices)
|
||||
}
|
||||
|
||||
func TestPriceFeedMigrateTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(migrateTestSuite))
|
||||
}
|
Loading…
Reference in New Issue
Block a user