Skip to content

Commit c1a4370

Browse files
committed
Track ALT address per launchpad currency
1 parent 85f833c commit c1a4370

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

pkg/code/data/currency/model.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ type MetadataRecord struct {
5353
FeesCore string
5454
SellFeeBps uint16
5555

56+
Alt string
57+
5658
CreatedBy string
5759
CreatedAt time.Time
5860
}
@@ -142,6 +144,10 @@ func (m *MetadataRecord) Validate() error {
142144
return errors.New("invalid buy sell bps")
143145
}
144146

147+
if len(m.Alt) == 0 {
148+
return errors.New("alt is required")
149+
}
150+
145151
if len(m.CreatedBy) == 0 {
146152
return errors.New("created by is required")
147153
}
@@ -188,6 +194,8 @@ func (m *MetadataRecord) Clone() *MetadataRecord {
188194
FeesCore: m.FeesCore,
189195
SellFeeBps: m.SellFeeBps,
190196

197+
Alt: m.Alt,
198+
191199
CreatedBy: m.CreatedBy,
192200
CreatedAt: m.CreatedAt,
193201
}
@@ -227,6 +235,8 @@ func (m *MetadataRecord) CopyTo(dst *MetadataRecord) {
227235
dst.FeesCore = m.FeesCore
228236
dst.SellFeeBps = m.SellFeeBps
229237

238+
dst.Alt = m.Alt
239+
230240
dst.CreatedBy = m.CreatedBy
231241
dst.CreatedAt = m.CreatedAt
232242
}

pkg/code/data/currency/postgres/model.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ type metadataModel struct {
8282
FeesCore string `db:"fees_core"`
8383
SellFeeBps uint16 `db:"sell_fee_bps"`
8484

85+
Alt string `db:"alt"`
86+
8587
CreatedBy string `db:"created_by"`
8688
CreatedAt time.Time `db:"created_at"`
8789
}
@@ -125,6 +127,8 @@ func toMetadataModel(obj *currency.MetadataRecord) (*metadataModel, error) {
125127
FeesCore: obj.FeesCore,
126128
SellFeeBps: obj.SellFeeBps,
127129

130+
Alt: obj.Alt,
131+
128132
CreatedBy: obj.CreatedBy,
129133
CreatedAt: obj.CreatedAt,
130134
}, nil
@@ -165,6 +169,8 @@ func fromMetadataModel(obj *metadataModel) *currency.MetadataRecord {
165169
FeesCore: obj.FeesCore,
166170
SellFeeBps: obj.SellFeeBps,
167171

172+
Alt: obj.Alt,
173+
168174
CreatedBy: obj.CreatedBy,
169175
CreatedAt: obj.CreatedAt,
170176
}
@@ -252,9 +258,9 @@ func (m *metadataModel) dbSave(ctx context.Context, db *sqlx.DB) error {
252258
return pgutil.ExecuteInTx(ctx, db, sql.LevelDefault, func(tx *sqlx.Tx) error {
253259
err := tx.QueryRowxContext(ctx,
254260
`INSERT INTO `+metadataTableName+`
255-
(name, symbol, description, image_url, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, created_by, created_at)
256-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23)
257-
RETURNING id, name, symbol, description, image_url, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, created_by, created_at`,
261+
(name, symbol, description, image_url, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, alt, created_by, created_at)
262+
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)
263+
RETURNING id, name, symbol, description, image_url, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, alt, created_by, created_at`,
258264
m.Name,
259265
m.Symbol,
260266
m.Description,
@@ -276,6 +282,7 @@ func (m *metadataModel) dbSave(ctx context.Context, db *sqlx.DB) error {
276282
m.BuyFeeBps,
277283
m.FeesCore,
278284
m.SellFeeBps,
285+
m.Alt,
279286
m.CreatedBy,
280287
m.CreatedAt,
281288
).StructScan(m)
@@ -355,7 +362,7 @@ func dbGetAllExchangeRatesForRange(ctx context.Context, db *sqlx.DB, symbol stri
355362
func dbGetMetadataByMint(ctx context.Context, db *sqlx.DB, mint string) (*metadataModel, error) {
356363
res := &metadataModel{}
357364
err := db.GetContext(ctx, res,
358-
`SELECT id, name, symbol, description, image_url, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, created_by, created_at
365+
`SELECT id, name, symbol, description, image_url, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, alt, created_by, created_at
359366
FROM `+metadataTableName+`
360367
WHERE mint = $1`,
361368
mint,

pkg/code/data/currency/postgres/store_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const (
6464
fees_core TEXT NOT NULL,
6565
sell_fee_bps INTEGER NOT NULL,
6666
67+
alt TEXT NOT NULL,
68+
6769
created_by TEXT NOT NULL,
6870
created_at TIMESTAMP WITH TIME ZONE NOT NULL
6971
);

pkg/code/data/currency/tests/tests.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ func testMetadataRoundTrip(t *testing.T, s currency.Store) {
149149
FeesCore: "5EcVYL8jHRKeeQqg6eYVBzc73ecH1PFzzaavoQBKRYy5",
150150
SellFeeBps: currencycreator.DefaultSellFeeBps,
151151

152+
Alt: "EkAeTCceLWbmZrAzVZanDJBtHSnkAWndMFgmTnUnVLRR",
153+
152154
CreatedBy: "jyyy4RpW3X5ApbW5G6vx9ZVPxhoUKGRLbZ4LxC47LYG",
153155
CreatedAt: time.Now(),
154156
}
@@ -223,6 +225,7 @@ func assertEquivalentMetadataRecords(t *testing.T, obj1, obj2 *currency.Metadata
223225
assert.Equal(t, obj1.BuyFeeBps, obj2.BuyFeeBps)
224226
assert.Equal(t, obj1.FeesCore, obj2.FeesCore)
225227
assert.Equal(t, obj1.SellFeeBps, obj2.SellFeeBps)
228+
assert.Equal(t, obj1.Alt, obj2.Alt)
226229
assert.Equal(t, obj1.CreatedBy, obj2.CreatedBy)
227230
assert.Equal(t, obj1.CreatedAt.Unix(), obj2.CreatedAt.Unix())
228231
}

pkg/code/transaction/alt.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"crypto/ed25519"
66

7-
"github.com/pkg/errors"
8-
97
"github.com/code-payments/code-server/pkg/code/common"
108
code_data "github.com/code-payments/code-server/pkg/code/data"
119
"github.com/code-payments/code-server/pkg/solana"
@@ -15,29 +13,17 @@ import (
1513
// GetAltForMint gets an address lookup table to operate in a versioned
1614
// transaction for the provided mint
1715
func GetAltForMint(ctx context.Context, data code_data.Provider, mint *common.Account) (solana.AddressLookupTable, error) {
18-
// todo: This would be tracked in a DB table
19-
var account *common.Account
20-
var err error
21-
switch mint.PublicKey().ToBase58() {
22-
case "52MNGpgvydSwCtC2H4qeiZXZ1TxEuRVCRGa8LAfk2kSj":
23-
account, err = common.NewAccountFromPublicKeyString("EkAeTCceLWbmZrAzVZanDJBtHSnkAWndMFgmTnUnVLRR")
24-
case "497Wy6cY9BjWBiaDHzJ7TcUZqF2gE1Qm7yXtSj1vSr5W":
25-
account, err = common.NewAccountFromPublicKeyString("3QLcDkhXMAKuRvCJuc6kcye4w6yyHaDs1dYcktcB1pRA")
26-
case "2o4PFbDZ73BihFraknfVTQeUtELKAeVUL4oa6bkrYU3A":
27-
account, err = common.NewAccountFromPublicKeyString("4bPdZB23pPYSg49H3fEMLSaqarQayvhpRJatxgv1P2JP")
28-
default:
29-
return solana.AddressLookupTable{}, errors.New("unsupported currency")
30-
}
16+
metadataRecord, err := data.GetCurrencyMetadata(ctx, mint.PublicKey().ToBase58())
3117
if err != nil {
3218
return solana.AddressLookupTable{}, err
3319
}
3420

35-
vmConfig, err := common.GetVmConfigForMint(ctx, data, mint)
21+
account, err := common.NewAccountFromPublicKeyString(metadataRecord.Alt)
3622
if err != nil {
3723
return solana.AddressLookupTable{}, err
3824
}
3925

40-
metadataRecord, err := data.GetCurrencyMetadata(ctx, mint.PublicKey().ToBase58())
26+
vmConfig, err := common.GetVmConfigForMint(ctx, data, mint)
4127
if err != nil {
4228
return solana.AddressLookupTable{}, err
4329
}

0 commit comments

Comments
 (0)