Skip to content

Commit 85f833c

Browse files
committed
Add utitilies for launchpad currency ALTs and accounts
1 parent d507f4c commit 85f833c

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

pkg/code/common/account.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
code_data "github.com/code-payments/code-server/pkg/code/data"
1515
"github.com/code-payments/code-server/pkg/code/data/account"
16+
"github.com/code-payments/code-server/pkg/code/data/currency"
1617
"github.com/code-payments/code-server/pkg/code/data/timelock"
1718
"github.com/code-payments/code-server/pkg/solana"
1819
"github.com/code-payments/code-server/pkg/solana/cvm"
@@ -529,6 +530,64 @@ func ValidateExternalTokenAccount(ctx context.Context, data code_data.Provider,
529530
}
530531
}
531532

533+
type LaunchpadCurrencyAccounts struct {
534+
Mint *Account
535+
CurrencyConfig *Account
536+
CurrencyConfigBump uint8
537+
LiquidityPool *Account
538+
LiquidityPoolBump uint8
539+
VaultBase *Account
540+
VaultBaseBump uint8
541+
VaultMint *Account
542+
VaultMintBump uint8
543+
FeesBase *Account
544+
FeesMint *Account
545+
}
546+
547+
func GetLaunchpadCurrencyAccounts(metadataRecord *currency.MetadataRecord) (*LaunchpadCurrencyAccounts, error) {
548+
mint, err := NewAccountFromPublicKeyString(metadataRecord.Mint)
549+
if err != nil {
550+
return nil, err
551+
}
552+
currencyConfig, err := NewAccountFromPublicKeyString(metadataRecord.CurrencyConfig)
553+
if err != nil {
554+
return nil, err
555+
}
556+
liquidityPool, err := NewAccountFromPublicKeyString(metadataRecord.LiquidityPool)
557+
if err != nil {
558+
return nil, err
559+
}
560+
vaultBase, err := NewAccountFromPublicKeyString(metadataRecord.VaultCore)
561+
if err != nil {
562+
return nil, err
563+
}
564+
vaultMint, err := NewAccountFromPublicKeyString(metadataRecord.VaultMint)
565+
if err != nil {
566+
return nil, err
567+
}
568+
feesBase, err := NewAccountFromPublicKeyString(metadataRecord.FeesCore)
569+
if err != nil {
570+
return nil, err
571+
}
572+
feesMint, err := NewAccountFromPublicKeyString(metadataRecord.FeesMint)
573+
if err != nil {
574+
return nil, err
575+
}
576+
return &LaunchpadCurrencyAccounts{
577+
Mint: mint,
578+
CurrencyConfig: currencyConfig,
579+
CurrencyConfigBump: metadataRecord.CurrencyConfigBump,
580+
LiquidityPool: liquidityPool,
581+
LiquidityPoolBump: metadataRecord.LiquidityPoolBump,
582+
VaultBase: vaultBase,
583+
VaultBaseBump: metadataRecord.VaultCoreBump,
584+
VaultMint: vaultMint,
585+
VaultMintBump: metadataRecord.VaultMintBump,
586+
FeesBase: feesBase,
587+
FeesMint: feesMint,
588+
}, nil
589+
}
590+
532591
func isOnCurve(pubKey ed25519.PublicKey) bool {
533592
if len(pubKey) != ed25519.PublicKeySize {
534593
return false

pkg/code/transaction/alt.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package transaction
2+
3+
import (
4+
"context"
5+
"crypto/ed25519"
6+
7+
"github.com/pkg/errors"
8+
9+
"github.com/code-payments/code-server/pkg/code/common"
10+
code_data "github.com/code-payments/code-server/pkg/code/data"
11+
"github.com/code-payments/code-server/pkg/solana"
12+
"github.com/code-payments/code-server/pkg/solana/system"
13+
)
14+
15+
// GetAltForMint gets an address lookup table to operate in a versioned
16+
// transaction for the provided mint
17+
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+
}
31+
if err != nil {
32+
return solana.AddressLookupTable{}, err
33+
}
34+
35+
vmConfig, err := common.GetVmConfigForMint(ctx, data, mint)
36+
if err != nil {
37+
return solana.AddressLookupTable{}, err
38+
}
39+
40+
metadataRecord, err := data.GetCurrencyMetadata(ctx, mint.PublicKey().ToBase58())
41+
if err != nil {
42+
return solana.AddressLookupTable{}, err
43+
}
44+
45+
currencyAccounts, err := common.GetLaunchpadCurrencyAccounts(metadataRecord)
46+
if err != nil {
47+
return solana.AddressLookupTable{}, err
48+
}
49+
50+
return solana.AddressLookupTable{
51+
PublicKey: account.PublicKey().ToBytes(),
52+
Addresses: []ed25519.PublicKey{
53+
vmConfig.Vm.PublicKey().ToBytes(),
54+
vmConfig.Omnibus.PublicKey().ToBytes(),
55+
mint.PublicKey().ToBytes(),
56+
currencyAccounts.CurrencyConfig.PublicKey().ToBytes(),
57+
currencyAccounts.LiquidityPool.PublicKey().ToBytes(),
58+
currencyAccounts.VaultBase.PublicKey().ToBytes(),
59+
currencyAccounts.VaultMint.PublicKey().ToBytes(),
60+
currencyAccounts.FeesBase.PublicKey().ToBytes(),
61+
currencyAccounts.FeesMint.PublicKey().ToBytes(),
62+
common.CoreMintAccount.PublicKey().ToBytes(),
63+
system.RentSysVar,
64+
system.RecentBlockhashesSysVar,
65+
},
66+
}, nil
67+
}

0 commit comments

Comments
 (0)