Skip to content

Commit 582ac1e

Browse files
author
Jeff Yanta
committed
Implement Currency service GetMints RPC
1 parent 1a8d7fc commit 582ac1e

File tree

5 files changed

+90
-5
lines changed

5 files changed

+90
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
filippo.io/edwards25519 v1.1.0
77
github.com/aws/aws-sdk-go-v2 v0.17.0
88
github.com/bits-and-blooms/bloom/v3 v3.1.0
9-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250704193024-5320c0a4c394
9+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250825171158-5f02a8a5924b
1010
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba
1111
github.com/emirpasic/gods v1.12.0
1212
github.com/envoyproxy/protoc-gen-validate v1.2.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
8080
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
8181
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
8282
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
83-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250704193024-5320c0a4c394 h1:N7jAqU3A0w4o55xT63ZW5xe14/4jpVb/59OzcW1xvj8=
84-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250704193024-5320c0a4c394/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
83+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250825171158-5f02a8a5924b h1:dwgr/zhcF7eZsBgRAX+AAjOhBdk9fEs1oO2csc0lI0U=
84+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250825171158-5f02a8a5924b/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
8585
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba h1:Bkp+gmeb6Y2PWXfkSCTMBGWkb2P1BujRDSjWeI+0j5I=
8686
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba/go.mod h1:jSiifpiBpyBQ8q2R0MGEbkSgWC6sbdRTyDBntmW+j1E=
8787
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=

pkg/code/common/mint.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import (
1515
var (
1616
CoreMintAccount, _ = NewAccountFromPublicKeyBytes(config.CoreMintPublicKeyBytes)
1717
CoreMintQuarksPerUnit = uint64(config.CoreMintQuarksPerUnit)
18-
CoreMintSymbol = config.CoreMintSymbol
1918
CoreMintDecimals = config.CoreMintDecimals
19+
CoreMintName = config.CoreMintName
20+
CoreMintSymbol = config.CoreMintSymbol
2021

2122
UsdcMintAccount, _ = NewAccountFromPublicKeyBytes(usdc.TokenMint)
2223
)

pkg/code/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ const (
1414
// Random values. Replace with real mint configuration
1515
CoreMintPublicKeyString = "DWYE8SQkpestTvpCxGNTCRjC2E9Kn6TCnu2SxkddrEEU"
1616
CoreMintQuarksPerUnit = uint64(usdc.QuarksPerUsdc)
17-
CoreMintSymbol = currency_lib.USDC
1817
CoreMintDecimals = usdc.Decimals
18+
CoreMintName = "USDC"
19+
CoreMintSymbol = currency_lib.USDC
1920

2021
// Random value. Replace with real subsidizer public keys
2122
SubsidizerPublicKey = "84ydcM4Yp59W6aZP6eSaKiAMaKidNLfb5k318sT2pm14"

pkg/code/server/currency/currency.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package currency
22

33
import (
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

2126
type 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+
62145
func (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

Comments
 (0)