@@ -2,6 +2,7 @@ package currency
22
33import (
44 "context"
5+ "strings"
56 "time"
67
78 "github.com/pkg/errors"
@@ -12,10 +13,14 @@ import (
1213
1314 currencypb "github.com/code-payments/code-protobuf-api/generated/go/currency/v1"
1415
16+ "github.com/code-payments/code-server/pkg/code/common"
1517 currency_util "github.com/code-payments/code-server/pkg/code/currency"
1618 code_data "github.com/code-payments/code-server/pkg/code/data"
1719 "github.com/code-payments/code-server/pkg/code/data/currency"
1820 "github.com/code-payments/code-server/pkg/grpc/client"
21+ "github.com/code-payments/code-server/pkg/solana"
22+ "github.com/code-payments/code-server/pkg/solana/currencycreator"
23+ "github.com/code-payments/code-server/pkg/solana/token"
1924)
2025
2126type currencyServer struct {
@@ -59,6 +64,84 @@ func (s *currencyServer) GetAllRates(ctx context.Context, req *currencypb.GetAll
5964 }, nil
6065}
6166
67+ func (s * currencyServer ) GetMints (ctx context.Context , req * currencypb.GetMintsRequest ) (* currencypb.GetMintsResponse , error ) {
68+ log := s .log .WithField ("method" , "GetMints" )
69+ log = client .InjectLoggingMetadata (ctx , log )
70+
71+ resp := & currencypb.GetMintsResponse {}
72+
73+ for _ , protoMintAddress := range req .Addresses {
74+ mintAccount , err := common .NewAccountFromProto (protoMintAddress )
75+ if err != nil {
76+ log .WithError (err ).Warn ("Invalid mint address" )
77+ return nil , status .Error (codes .Internal , "" )
78+ }
79+
80+ log = log .WithField ("mint" , mintAccount .PublicKey ().ToBase58 ())
81+
82+ var protoMetadata * currencypb.Mint
83+ switch mintAccount .PublicKey ().ToBase58 () {
84+ case common .CoreMintAccount .PublicKey ().ToBase58 ():
85+ protoMetadata = & currencypb.Mint {
86+ Address : protoMintAddress ,
87+ Decimals : uint32 (common .CoreMintDecimals ),
88+ Name : common .CoreMintName ,
89+ Symbol : strings .ToUpper (string (common .CoreMintSymbol )),
90+ VmMetadata : & currencypb.VmMintMetadata {
91+ Vm : common .CodeVmAccount .ToProto (),
92+ Authority : common .GetSubsidizer ().ToProto (),
93+ LockDurationInDays : 21 ,
94+ },
95+ }
96+ case "52MNGpgvydSwCtC2H4qeiZXZ1TxEuRVCRGa8LAfk2kSj" : // todo: load from DB populated by worker
97+ authorityAccount , _ := common .NewAccountFromPublicKeyString ("jfy1btcfsjSn2WCqLVaxiEjp4zgmemGyRsdCPbPwnZV" )
98+ jeffyVaultAccount , _ := common .NewAccountFromPublicKeyString ("BFDanLgELhpCCGTtaa7c8WGxTXcTxgwkf9DMQd4qheSK" )
99+ coreMintVaultAccount , _ := common .NewAccountFromPublicKeyString ("A9NVHVuorNL4y2YFxdwdU3Hqozxw1Y1YJ81ZPxJsRrT4" )
100+ vmAccount , _ := common .NewAccountFromPublicKeyString ("Bii3UFB9DzPq6UxgewF5iv9h1Gi8ZnP6mr7PtocHGNta" )
101+
102+ var tokenAccount token.Account
103+ ai , err := s .data .GetBlockchainAccountInfo (ctx , jeffyVaultAccount .PublicKey ().ToBase58 (), solana .CommitmentFinalized )
104+ if err != nil {
105+ log .Warn ("Failure getting Jeffy vault balance" )
106+ return nil , status .Error (codes .Internal , "" )
107+ }
108+ tokenAccount .Unmarshal (ai .Data )
109+ jeffyVaultBalance := tokenAccount .Amount
110+
111+ ai , err = s .data .GetBlockchainAccountInfo (ctx , coreMintVaultAccount .PublicKey ().ToBase58 (), solana .CommitmentFinalized )
112+ if err != nil {
113+ log .Warn ("Failure getting USDC vault balance" )
114+ return nil , status .Error (codes .Internal , "" )
115+ }
116+ tokenAccount .Unmarshal (ai .Data )
117+ coreMintVaultBalance := tokenAccount .Amount
118+
119+ protoMetadata = & currencypb.Mint {
120+ Address : protoMintAddress ,
121+ Decimals : currencycreator .DefaultMintDecimals ,
122+ Name : "Jeffy" ,
123+ Symbol : "JFY" ,
124+ VmMetadata : & currencypb.VmMintMetadata {
125+ Vm : vmAccount .ToProto (),
126+ Authority : authorityAccount .ToProto (),
127+ LockDurationInDays : 21 ,
128+ },
129+ CurrencyCreatorMetadata : & currencypb.CurrencyCreatorMintMetadata {
130+ SupplyFromBonding : currencycreator .DefaultMintMaxQuarkSupply - jeffyVaultBalance ,
131+ CoreMintTokensLocked : coreMintVaultBalance ,
132+ BuyFeeBps : currencycreator .DefaultBuyFeeBps ,
133+ SellFeeBps : currencycreator .DefaultSellFeeBps ,
134+ },
135+ }
136+ default :
137+ return & currencypb.GetMintsResponse {Result : currencypb .GetMintsResponse_NOT_FOUND }, nil
138+ }
139+
140+ resp .MetadataByAddress [common .CoreMintAccount .PublicKey ().ToBase58 ()] = protoMetadata
141+ }
142+ return & currencypb.GetMintsResponse {}, nil
143+ }
144+
62145func (s * currencyServer ) LoadExchangeRatesForTime (ctx context.Context , t time.Time ) (* currency.MultiRateRecord , error ) {
63146 record , err := s .data .GetAllExchangeRates (ctx , t )
64147 if err != nil {
0 commit comments