|
| 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