Skip to content

Commit 699634b

Browse files
committed
Add support for more common USD stable coins
1 parent 9c8923f commit 699634b

File tree

7 files changed

+214
-180
lines changed

7 files changed

+214
-180
lines changed

pkg/code/common/mint.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99

1010
"github.com/code-payments/code-server/pkg/code/config"
1111
"github.com/code-payments/code-server/pkg/usdc"
12+
"github.com/code-payments/code-server/pkg/usdg"
13+
"github.com/code-payments/code-server/pkg/usdt"
1214
)
1315

1416
var (
@@ -59,3 +61,12 @@ func StrToQuarks(val string) (int64, error) {
5961

6062
return int64(wholeUnits)*int64(CoreMintQuarksPerUnit) + int64(quarks), nil
6163
}
64+
65+
func IsCoreMintUsdStableCoin() bool {
66+
switch CoreMintAccount.PublicKey().ToBase58() {
67+
case usdc.Mint, usdg.Mint, usdt.Mint:
68+
return true
69+
default:
70+
return false
71+
}
72+
}

pkg/code/data/external.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/code-payments/code-server/pkg/currency/fixer"
1313
"github.com/code-payments/code-server/pkg/metrics"
1414
"github.com/code-payments/code-server/pkg/usdc"
15+
"github.com/code-payments/code-server/pkg/usdg"
16+
"github.com/code-payments/code-server/pkg/usdt"
1517
)
1618

1719
const (
@@ -48,9 +50,11 @@ func (dp *WebProvider) GetCurrentExchangeRatesFromExternalProviders(ctx context.
4850

4951
coinGeckoRates := make(map[string]float64)
5052
var err error
51-
if config.CoreMintPublicKeyString == usdc.Mint {
53+
54+
switch config.CoreMintPublicKeyString {
55+
case usdc.Mint, usdg.Mint, usdt.Mint:
5256
coinGeckoRates[string(currency_lib.USD)] = 1.0
53-
} else {
57+
default:
5458
coinGeckoData, err := dp.coinGecko.GetCurrentRates(ctx, string(config.CoreMintSymbol))
5559
if err != nil {
5660
return nil, err
@@ -80,9 +84,10 @@ func (dp *WebProvider) GetPastExchangeRatesFromExternalProviders(ctx context.Con
8084
coinGeckoRates := make(map[string]float64)
8185
ts := t
8286
var err error
83-
if config.CoreMintPublicKeyString == usdc.Mint {
87+
switch config.CoreMintPublicKeyString {
88+
case usdc.Mint, usdg.Mint, usdt.Mint:
8489
coinGeckoRates[string(currency_lib.USD)] = 1.0
85-
} else {
90+
default:
8691
coinGeckoData, err := dp.coinGecko.GetCurrentRates(ctx, string(config.CoreMintSymbol))
8792
if err != nil {
8893
return nil, err
@@ -112,7 +117,8 @@ func computeAllExchangeRates(coreMintRates map[string]float64, usdRates map[stri
112117
if !ok {
113118
return nil, errors.New("usd rate missing")
114119
}
115-
if config.CoreMintPublicKeyString == usdc.Mint {
120+
switch config.CoreMintPublicKeyString {
121+
case usdc.Mint, usdg.Mint, usdt.Mint:
116122
coreMintToUsd = 1.0
117123
}
118124

pkg/code/server/account/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func (s *server) LinkAdditionalAccounts(ctx context.Context, req *accountpb.Link
9797
log := s.log.WithField("method", "LinkAdditionalAccounts")
9898
log = client.InjectLoggingMetadata(ctx, log)
9999

100-
if common.CoreMintAccount.PublicKey().ToBase58() == common.UsdcMintAccount.PublicKey().ToBase58() {
101-
log.Warn("core mint account is usdc")
100+
if common.IsCoreMintUsdStableCoin() {
101+
log.Warn("core mint account is usd stable coin")
102102
return nil, status.Error(codes.Unavailable, "")
103103
}
104104

pkg/code/server/transaction/swap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
4343
return handleSwapError(streamer, status.Error(codes.Unavailable, ""))
4444
}
4545

46-
if common.CoreMintAccount.PublicKey().ToBase58() == common.UsdcMintAccount.PublicKey().ToBase58() {
47-
log.Warn("core mint account is usdc")
46+
if common.IsCoreMintUsdStableCoin() {
47+
log.Warn("core mint account is usd stable coin")
4848
return handleSwapError(streamer, status.Error(codes.Unavailable, ""))
4949
}
5050

0 commit comments

Comments
 (0)