Skip to content
Merged
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
1 change: 1 addition & 0 deletions ocp/data/currency/metadata/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (s *store) SaveMetadata(ctx context.Context, data *currency.MetadataRecord)
cloned.BillColors = append([]string(nil), data.BillColors...)
cloned.SocialLinks = append([]currency.SocialLink(nil), data.SocialLinks...)
cloned.Alt = data.Alt
cloned.IsDiscoverable = data.IsDiscoverable
cloned.State = data.State
cloned.Version = item.Version + 1

Expand Down
21 changes: 14 additions & 7 deletions ocp/data/currency/metadata/postgres/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type model struct {

Alt string `db:"alt"`

IsDiscoverable bool `db:"is_discoverable"`

State uint8 `db:"state"`
Version uint64 `db:"version"`

Expand Down Expand Up @@ -99,6 +101,8 @@ func toModel(obj *currency.MetadataRecord) (*model, error) {

Alt: obj.Alt,

IsDiscoverable: obj.IsDiscoverable,

State: uint8(obj.State),
Version: obj.Version,

Expand Down Expand Up @@ -147,6 +151,8 @@ func fromModel(obj *model) *currency.MetadataRecord {

Alt: obj.Alt,

IsDiscoverable: obj.IsDiscoverable,

State: currency.MetadataState(obj.State),
Version: obj.Version,

Expand Down Expand Up @@ -176,15 +182,15 @@ func (m *model) dbSave(ctx context.Context, db *sqlx.DB) error {
return pgutil.ExecuteInTx(ctx, db, sql.LevelDefault, func(tx *sqlx.Tx) error {
err := tx.QueryRowxContext(ctx,
`INSERT INTO `+tableName+`
(name, symbol, description, image_url, bill_colors, social_links, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, state, version, created_by, created_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23 + 1, $24, $25)
(name, symbol, description, image_url, bill_colors, social_links, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, is_discoverable, state, version, created_by, created_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24 + 1, $25, $26)

ON CONFLICT (mint)
DO UPDATE
SET description = $3, image_url = $4, bill_colors = $5, social_links = $6, alt = $21, state = $22, version = `+tableName+`.version + 1
WHERE `+tableName+`.mint = $9 AND `+tableName+`.version = $23
SET description = $3, image_url = $4, bill_colors = $5, social_links = $6, alt = $21, is_discoverable = $22, state = $23, version = `+tableName+`.version + 1
WHERE `+tableName+`.mint = $9 AND `+tableName+`.version = $24

RETURNING id, name, symbol, description, image_url, bill_colors, social_links, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, state, version, created_by, created_at`,
RETURNING id, name, symbol, description, image_url, bill_colors, social_links, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, is_discoverable, state, version, created_by, created_at`,
m.Name,
m.Symbol,
m.Description,
Expand All @@ -206,6 +212,7 @@ func (m *model) dbSave(ctx context.Context, db *sqlx.DB) error {
m.VaultCoreBump,
m.SellFeeBps,
m.Alt,
m.IsDiscoverable,
m.State,
m.Version,
m.CreatedBy,
Expand All @@ -225,7 +232,7 @@ func dbGetAllMetadataByState(ctx context.Context, db *sqlx.DB, state currency.Me
res := []*model{}

query := `SELECT
id, name, symbol, description, image_url, bill_colors, social_links, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, state, version, created_by, created_at
id, name, symbol, description, image_url, bill_colors, social_links, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, is_discoverable, state, version, created_by, created_at
FROM ` + tableName + `
WHERE state = $1`

Expand All @@ -246,7 +253,7 @@ func dbGetAllMetadataByState(ctx context.Context, db *sqlx.DB, state currency.Me
func dbGetMetadataByMint(ctx context.Context, db *sqlx.DB, mint string) (*model, error) {
res := &model{}
err := db.GetContext(ctx, res,
`SELECT id, name, symbol, description, image_url, bill_colors, social_links, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, state, version, created_by, created_at
`SELECT id, name, symbol, description, image_url, bill_colors, social_links, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, is_discoverable, state, version, created_by, created_at
FROM `+tableName+`
WHERE mint = $1`,
mint,
Expand Down
2 changes: 2 additions & 0 deletions ocp/data/currency/metadata/postgres/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const (

alt TEXT NOT NULL,

is_discoverable BOOLEAN NOT NULL DEFAULT TRUE,

state INTEGER NOT NULL,
version BIGINT NOT NULL,

Expand Down
2 changes: 1 addition & 1 deletion ocp/data/currency/metadata/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type Store interface {
// SaveMetadata creates or updates currency creator metadata in the store.
// On insert, Version is set to 1. On update, only mutable fields (Description,
// ImageUrl, BillColors, SocialLinks, Alt, State) are updated and Version is incremented.
// ImageUrl, BillColors, SocialLinks, Alt, IsDiscoverable, State) are updated and Version is incremented.
// ErrStaleMetadataVersion is returned when the provided version doesn't match.
SaveMetadata(ctx context.Context, record *currency.MetadataRecord) error

Expand Down
9 changes: 9 additions & 0 deletions ocp/data/currency/metadata/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func testMetadataRoundTrip(t *testing.T, s metadata.Store) {

Alt: "EkAeTCceLWbmZrAzVZanDJBtHSnkAWndMFgmTnUnVLRR",

IsDiscoverable: true,

CreatedBy: "jyyy4RpW3X5ApbW5G6vx9ZVPxhoUKGRLbZ4LxC47LYG",
CreatedAt: time.Now(),
}
Expand All @@ -84,6 +86,7 @@ func testMetadataRoundTrip(t *testing.T, s metadata.Store) {
actual, err := s.GetMetadata(context.Background(), expected.Mint)
require.NoError(t, err)
assertEquivalentRecords(t, cloned, actual)
assert.True(t, actual.IsDiscoverable)
assert.EqualValues(t, currency.MetadataStateUnknown, actual.State)
assert.EqualValues(t, 1, actual.Version)
}
Expand Down Expand Up @@ -728,6 +731,8 @@ func testMetadataSaveWithVersioning(t *testing.T, s metadata.Store) {

Alt: "veralt11111111111111111111111111111111111111111",

IsDiscoverable: true,

CreatedBy: "vercreator1",
CreatedAt: time.Now(),
}
Expand All @@ -736,6 +741,7 @@ func testMetadataSaveWithVersioning(t *testing.T, s metadata.Store) {
require.NoError(t, s.SaveMetadata(context.Background(), record))
assert.EqualValues(t, 1, record.Version)
assert.EqualValues(t, currency.MetadataStateUnknown, record.State)
assert.True(t, record.IsDiscoverable)

// Update mutable fields and save again with correct version
record.State = currency.MetadataStateAvailable
Expand All @@ -749,6 +755,7 @@ func testMetadataSaveWithVersioning(t *testing.T, s metadata.Store) {
{Type: currency.SocialLinkTypeDiscord, Value: "updateddiscord"},
}
record.Alt = "updatedalt1111111111111111111111111111111111111"
record.IsDiscoverable = false
require.NoError(t, s.SaveMetadata(context.Background(), record))
assert.EqualValues(t, 2, record.Version)
assert.EqualValues(t, currency.MetadataStateAvailable, record.State)
Expand All @@ -768,6 +775,7 @@ func testMetadataSaveWithVersioning(t *testing.T, s metadata.Store) {
{Type: currency.SocialLinkTypeDiscord, Value: "updateddiscord"},
}, actual.SocialLinks)
assert.Equal(t, "updatedalt1111111111111111111111111111111111111", actual.Alt)
assert.False(t, actual.IsDiscoverable)

// Verify immutable fields were preserved
assert.Equal(t, "Versioned", actual.Name)
Expand Down Expand Up @@ -827,6 +835,7 @@ func assertEquivalentRecords(t *testing.T, obj1, obj2 *currency.MetadataRecord)
assert.Equal(t, obj1.VaultCoreBump, obj2.VaultCoreBump)
assert.Equal(t, obj1.SellFeeBps, obj2.SellFeeBps)
assert.Equal(t, obj1.Alt, obj2.Alt)
assert.Equal(t, obj1.IsDiscoverable, obj2.IsDiscoverable)
assert.Equal(t, obj1.State, obj2.State)
assert.Equal(t, obj1.CreatedBy, obj2.CreatedBy)
assert.Equal(t, obj1.CreatedAt.Unix(), obj2.CreatedAt.Unix())
Expand Down
6 changes: 6 additions & 0 deletions ocp/data/currency/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ type MetadataRecord struct {

Alt string

IsDiscoverable bool

State MetadataState
Version uint64

Expand Down Expand Up @@ -231,6 +233,8 @@ func (m *MetadataRecord) Clone() *MetadataRecord {

Alt: m.Alt,

IsDiscoverable: m.IsDiscoverable,

State: m.State,
Version: m.Version,

Expand Down Expand Up @@ -273,6 +277,8 @@ func (m *MetadataRecord) CopyTo(dst *MetadataRecord) {

dst.Alt = m.Alt

dst.IsDiscoverable = m.IsDiscoverable

dst.State = m.State
dst.Version = m.Version

Expand Down
4 changes: 4 additions & 0 deletions ocp/rpc/currency/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func (s *currencyServer) Discover(req *currencypb.DiscoverRequest, stream curren
continue
}

if !record.IsDiscoverable {
continue
}

reserveState, ok := cachedReserves[record.Mint]
if !ok || reserveState.SupplyFromBonding < minDiscoverySupply {
continue
Expand Down
2 changes: 2 additions & 0 deletions ocp/rpc/currency/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ func (s *currencyServer) Launch(ctx context.Context, req *currencypb.LaunchReque

Alt: base58.Encode(system.ProgramKey[:]), // ALT filled in later due to recent slot requirements

IsDiscoverable: true,

State: currency.MetadataStateWaitingForInitialPurchase,

CreatedBy: ownerAccount.PublicKey().ToBase58(),
Expand Down
Loading