Skip to content

Commit 6333d1d

Browse files
akanterLightspark Eng
authored andcommitted
SP-2735: Replace currency config ents with dataclasses + token fund-in enum additions (#25988)
## Summary - Replace `CurrencyConfig`, `CurrencyConversionConfig`, and `NetworkCurrencyConfig` ent entities with frozen Python `@dataclass` types in `sparklib/money/currency_config_types.py` - Configs are backed by Quart `current_app.config` via a centralized `_app_config()` helper (single `current_app` import point) - Classmethod API: `CurrencyConfig.get(unit)`, `CurrencyConversionConfig.get(from, to)`, `CurrencyConversionConfig.is_supported(from, to)` - Synchronous `currency_service.py` wrapper in paycore accepts `CurrencyUnit | str` and implements config-then-fallback pattern (check CurrencyConfig first, fall back to CurrencyUnit enum methods) - `quote_utils.py` exchange rate logic now uses `CurrencyUnit.X.value` enum constants instead of raw strings - Fold non-ent-schema changes from #25494: USDB currency, SPARK_TESTNET → SPARK_REGTEST rename, new flow/settlement types ## Test plan - [x] 16 unit tests in `test_currency_config_types.py` covering all dataclass helpers - [x] Updated `test_create_send_quote_v2.py` for new currency code handling - [x] Full paycore test suite passes Fixes SP-2735 --- 🤖 *bonded-keystone-2* | [Dashboard](https://zeus.dev.dev.sparkinfra.net/#/instance?id=bonded-keystone-2) | [Feedback](https://zeus.dev.dev.sparkinfra.net/feedback) GitOrigin-RevId: 3a71bc7c836e1190b7a41fb5459afa7db4698818
1 parent f9d0f79 commit 6333d1d

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

packages/core/src/utils/currency.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const CurrencyUnit = {
5555
PKR: "PKR",
5656
USDT: "USDT",
5757
USDC: "USDC",
58+
USDB: "USDB",
5859

5960
Bitcoin: "BITCOIN",
6061
Microbitcoin: "MICROBITCOIN",
@@ -79,6 +80,7 @@ export const CurrencyUnit = {
7980
Pkr: "PKR",
8081
Usdt: "USDT",
8182
Usdc: "USDC",
83+
Usdb: "USDB",
8284
} as const;
8385

8486
export type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
@@ -141,6 +143,7 @@ const standardUnitConversionObj = {
141143
[CurrencyUnit.PKR]: (v: number) => v,
142144
[CurrencyUnit.USDT]: (v: number) => v,
143145
[CurrencyUnit.USDC]: (v: number) => v,
146+
[CurrencyUnit.USDB]: (v: number) => v,
144147
};
145148

146149
/* Round without decimals since we're returning cents: */
@@ -202,6 +205,7 @@ const CONVERSION_MAP = {
202205
[CurrencyUnit.PKR]: toBitcoinConversion,
203206
[CurrencyUnit.USDT]: toBitcoinConversion,
204207
[CurrencyUnit.USDC]: toBitcoinConversion,
208+
[CurrencyUnit.USDB]: toBitcoinConversion,
205209
},
206210
[CurrencyUnit.MICROBITCOIN]: {
207211
[CurrencyUnit.BITCOIN]: (v: number) => v / 1_000_000,
@@ -247,6 +251,7 @@ const CONVERSION_MAP = {
247251
[CurrencyUnit.PKR]: toMicrobitcoinConversion,
248252
[CurrencyUnit.USDT]: toMicrobitcoinConversion,
249253
[CurrencyUnit.USDC]: toMicrobitcoinConversion,
254+
[CurrencyUnit.USDB]: toMicrobitcoinConversion,
250255
},
251256
[CurrencyUnit.MILLIBITCOIN]: {
252257
[CurrencyUnit.BITCOIN]: (v: number) => v / 1_000,
@@ -292,6 +297,7 @@ const CONVERSION_MAP = {
292297
[CurrencyUnit.PKR]: toMillibitcoinConversion,
293298
[CurrencyUnit.USDT]: toMillibitcoinConversion,
294299
[CurrencyUnit.USDC]: toMillibitcoinConversion,
300+
[CurrencyUnit.USDB]: toMillibitcoinConversion,
295301
},
296302
[CurrencyUnit.MILLISATOSHI]: {
297303
[CurrencyUnit.BITCOIN]: (v: number) => v / 100_000_000_000,
@@ -337,6 +343,7 @@ const CONVERSION_MAP = {
337343
[CurrencyUnit.PKR]: toMillisatoshiConversion,
338344
[CurrencyUnit.USDT]: toMillisatoshiConversion,
339345
[CurrencyUnit.USDC]: toMillisatoshiConversion,
346+
[CurrencyUnit.USDB]: toMillisatoshiConversion,
340347
},
341348
[CurrencyUnit.NANOBITCOIN]: {
342349
[CurrencyUnit.BITCOIN]: (v: number) => v / 1_000_000_000,
@@ -382,6 +389,7 @@ const CONVERSION_MAP = {
382389
[CurrencyUnit.PKR]: toNanobitcoinConversion,
383390
[CurrencyUnit.USDT]: toNanobitcoinConversion,
384391
[CurrencyUnit.USDC]: toNanobitcoinConversion,
392+
[CurrencyUnit.USDB]: toNanobitcoinConversion,
385393
},
386394
[CurrencyUnit.SATOSHI]: {
387395
[CurrencyUnit.BITCOIN]: (v: number) => v / 100_000_000,
@@ -427,6 +435,7 @@ const CONVERSION_MAP = {
427435
[CurrencyUnit.PKR]: toSatoshiConversion,
428436
[CurrencyUnit.USDT]: toSatoshiConversion,
429437
[CurrencyUnit.USDC]: toSatoshiConversion,
438+
[CurrencyUnit.USDB]: toSatoshiConversion,
430439
},
431440
[CurrencyUnit.USD]: standardUnitConversionObj,
432441
[CurrencyUnit.MXN]: standardUnitConversionObj,
@@ -465,6 +474,7 @@ const CONVERSION_MAP = {
465474
[CurrencyUnit.PKR]: standardUnitConversionObj,
466475
[CurrencyUnit.USDT]: standardUnitConversionObj,
467476
[CurrencyUnit.USDC]: standardUnitConversionObj,
477+
[CurrencyUnit.USDB]: standardUnitConversionObj,
468478
};
469479

470480
export function convertCurrencyAmountValue(
@@ -563,6 +573,7 @@ export type CurrencyMap = {
563573
[CurrencyUnit.PKR]: number;
564574
[CurrencyUnit.USDT]: number;
565575
[CurrencyUnit.USDC]: number;
576+
[CurrencyUnit.USDB]: number;
566577
[CurrencyUnit.FUTURE_VALUE]: number;
567578
formatted: {
568579
sats: string;
@@ -611,6 +622,7 @@ export type CurrencyMap = {
611622
[CurrencyUnit.PKR]: string;
612623
[CurrencyUnit.USDT]: string;
613624
[CurrencyUnit.USDC]: string;
625+
[CurrencyUnit.USDB]: string;
614626
[CurrencyUnit.FUTURE_VALUE]: string;
615627
};
616628
isZero: boolean;
@@ -843,6 +855,7 @@ function convertCurrencyAmountValues(
843855
nbtc: CurrencyUnit.NANOBITCOIN,
844856
usdt: CurrencyUnit.USDT,
845857
usdc: CurrencyUnit.USDC,
858+
usdb: CurrencyUnit.USDB,
846859
};
847860
return Object.entries(namesToUnits).reduce(
848861
(acc, [name, unit]) => {
@@ -933,6 +946,7 @@ export function mapCurrencyAmount(
933946
pkr,
934947
usdt,
935948
usdc,
949+
usdb,
936950
} = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
937951

938952
const mapWithCurrencyUnits = {
@@ -979,6 +993,7 @@ export function mapCurrencyAmount(
979993
[CurrencyUnit.NANOBITCOIN]: nbtc,
980994
[CurrencyUnit.USDT]: usdt,
981995
[CurrencyUnit.USDC]: usdc,
996+
[CurrencyUnit.USDB]: usdb,
982997
[CurrencyUnit.FUTURE_VALUE]: NaN,
983998
formatted: {
984999
[CurrencyUnit.BITCOIN]: formatCurrencyStr({
@@ -1153,6 +1168,10 @@ export function mapCurrencyAmount(
11531168
value: usdc,
11541169
unit: CurrencyUnit.USDC,
11551170
}),
1171+
[CurrencyUnit.USDB]: formatCurrencyStr({
1172+
value: usdb,
1173+
unit: CurrencyUnit.USDB,
1174+
}),
11561175
[CurrencyUnit.FUTURE_VALUE]: "-",
11571176
},
11581177
};
@@ -1237,6 +1256,8 @@ export const abbrCurrencyUnit = (unit: CurrencyUnitType) => {
12371256
return "USDT";
12381257
case CurrencyUnit.USDC:
12391258
return "USDC";
1259+
case CurrencyUnit.USDB:
1260+
return "USDB";
12401261
case CurrencyUnit.BRL:
12411262
return "BRL";
12421263
case CurrencyUnit.CAD:

0 commit comments

Comments
 (0)