Compare commits
No commits in common. "09954d967f6721c8a30ecb1c3c8d66d583063b97" and "c2cfd0fe449353521d0e9a2b550c67dac3187cf7" have entirely different histories.
09954d967f
...
c2cfd0fe44
@ -39,7 +39,5 @@ DEFAULT_MPESA_ASSET=cUSD
|
|||||||
MPESA_BEARER_TOKEN=eyJeSIsInRcCI6IkpXVCJ.yJwdWJsaWNLZXkiOiIwrrrrrr
|
MPESA_BEARER_TOKEN=eyJeSIsInRcCI6IkpXVCJ.yJwdWJsaWNLZXkiOiIwrrrrrr
|
||||||
MPESA_ONRAMP_BASE=https://pretium.v1.grassecon.net
|
MPESA_ONRAMP_BASE=https://pretium.v1.grassecon.net
|
||||||
|
|
||||||
# Known stable voucher addresses (USDm, USD₮)
|
# Known stable voucher addresses (USDT, USDm)
|
||||||
STABLE_VOUCHER_ADDRESSES=0x765DE816845861e75A25fCA122bb6898B8B1282a,0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e
|
STABLE_VOUCHER_ADDRESSES=0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e,0x765DE816845861e75A25fCA122bb6898B8B1282a
|
||||||
DEFAULT_STABLE_VOUCHER_ADDRESS=0x765DE816845861e75A25fCA122bb6898B8B1282a
|
|
||||||
DEFAULT_STABLE_VOUCHER_DECIMALS=18
|
|
||||||
|
|||||||
@ -142,11 +142,3 @@ func StableVoucherAddresses() []string {
|
|||||||
|
|
||||||
return parsed
|
return parsed
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultStableVoucherAddress() string {
|
|
||||||
return env.GetEnv("DEFAULT_STABLE_VOUCHER_ADDRESS", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func DefaultStableVoucherDecimals() string {
|
|
||||||
return env.GetEnv("DEFAULT_STABLE_VOUCHER_DECIMALS", "")
|
|
||||||
}
|
|
||||||
|
|||||||
@ -206,7 +206,7 @@ func (h *MenuHandlers) CalculateCreditAndDebt(ctx context.Context, sym string, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Credit calculation: How much Active Token that can be swapped for a stable coin
|
// Credit calculation: How much Active Token (such as ALF) that can be swapped for a stable coin
|
||||||
// + any stables sendable to Pretium (in KSH value)
|
// + any stables sendable to Pretium (in KSH value)
|
||||||
scaledCredit := "0"
|
scaledCredit := "0"
|
||||||
|
|
||||||
@ -214,10 +214,10 @@ func (h *MenuHandlers) CalculateCreditAndDebt(ctx context.Context, sym string, i
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
// do a swap quote for default stable coin from active voucher
|
// do a swap quote to get the max I can get when I swap my active voucher
|
||||||
stableAddress := config.DefaultStableVoucherAddress()
|
// for a stable coin (say I can get 4 USD). Then I add that to my exisitng
|
||||||
stableDecimals := config.DefaultStableVoucherDecimals()
|
// stable coins and covert to Ksh
|
||||||
|
stableAddress := stableAddresses[0]
|
||||||
r, err := h.accountService.GetPoolSwapQuote(ctx, finalAmountStr, string(publicKey), string(activeAddress), string(activePoolAddress), stableAddress)
|
r, err := h.accountService.GetPoolSwapQuote(ctx, finalAmountStr, string(publicKey), string(activeAddress), string(activePoolAddress), stableAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||||
@ -227,7 +227,7 @@ func (h *MenuHandlers) CalculateCreditAndDebt(ctx context.Context, sym string, i
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
finalQuote := store.ScaleDownBalance(r.OutValue, stableDecimals)
|
finalQuote := store.ScaleDownBalance(r.OutValue, "6")
|
||||||
|
|
||||||
scaledCredit = store.AddDecimalStrings(scaledCredit, finalQuote)
|
scaledCredit = store.AddDecimalStrings(scaledCredit, finalQuote)
|
||||||
|
|
||||||
|
|||||||
@ -161,7 +161,7 @@ func (h *MenuHandlers) ConfirmDebtRemoval(ctx context.Context, sym string, input
|
|||||||
userStore := h.userdataStore
|
userStore := h.userdataStore
|
||||||
|
|
||||||
// Fetch session data
|
// Fetch session data
|
||||||
_, _, activeSym, activeAddress, publicKey, activeDecimal, err := h.getSessionData(ctx, sessionId)
|
_, _, activeSym, activeAddress, publicKey, _, err := h.getSessionData(ctx, sessionId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
@ -172,19 +172,12 @@ func (h *MenuHandlers) ConfirmDebtRemoval(ctx context.Context, sym string, input
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve active pool
|
swapData, err := store.ReadSwapPreviewData(ctx, userStore, sessionId)
|
||||||
activePoolAddress, _, err := h.resolveActivePoolDetails(ctx, sessionId)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
swapMaxAmount, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SWAP_MAX_AMOUNT)
|
maxValue, err := strconv.ParseFloat(swapData.ActiveSwapMaxAmount, 64)
|
||||||
if err != nil {
|
|
||||||
logg.ErrorCtxf(ctx, "failed to read swapMaxAmount entry with", "key", storedb.DATA_ACTIVE_SWAP_MAX_AMOUNT, "error", err)
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
maxValue, err := strconv.ParseFloat(string(swapMaxAmount), 64)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "Failed to convert the swapMaxAmount to a float", "error", err)
|
logg.ErrorCtxf(ctx, "Failed to convert the swapMaxAmount to a float", "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
@ -198,7 +191,7 @@ func (h *MenuHandlers) ConfirmDebtRemoval(ctx context.Context, sym string, input
|
|||||||
}
|
}
|
||||||
|
|
||||||
var finalAmountStr string
|
var finalAmountStr string
|
||||||
if inputStr == string(swapMaxAmount) {
|
if inputStr == swapData.ActiveSwapMaxAmount {
|
||||||
finalAmountStr = string(payDebtVoucher.Balance)
|
finalAmountStr = string(payDebtVoucher.Balance)
|
||||||
} else {
|
} else {
|
||||||
finalAmountStr, err = store.ParseAndScaleAmount(inputStr, payDebtVoucher.TokenDecimals)
|
finalAmountStr, err = store.ParseAndScaleAmount(inputStr, payDebtVoucher.TokenDecimals)
|
||||||
@ -214,7 +207,7 @@ func (h *MenuHandlers) ConfirmDebtRemoval(ctx context.Context, sym string, input
|
|||||||
}
|
}
|
||||||
|
|
||||||
// call the API to get the quote
|
// call the API to get the quote
|
||||||
r, err := h.accountService.GetPoolSwapQuote(ctx, finalAmountStr, string(publicKey), payDebtVoucher.TokenAddress, string(activePoolAddress), string(activeAddress))
|
r, err := h.accountService.GetPoolSwapQuote(ctx, finalAmountStr, string(publicKey), payDebtVoucher.TokenAddress, swapData.ActivePoolAddress, string(activeAddress))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||||
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
||||||
@ -223,8 +216,8 @@ func (h *MenuHandlers) ConfirmDebtRemoval(ctx context.Context, sym string, input
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale down the quoted amount (for the AT)
|
// Scale down the quoted amount
|
||||||
quoteAmountStr := store.ScaleDownBalance(r.OutValue, string(activeDecimal))
|
quoteAmountStr := store.ScaleDownBalance(r.OutValue, swapData.ActiveSwapFromDecimal)
|
||||||
|
|
||||||
// Format to 2 decimal places
|
// Format to 2 decimal places
|
||||||
qouteStr, _ := store.TruncateDecimalString(string(quoteAmountStr), 2)
|
qouteStr, _ := store.TruncateDecimalString(string(quoteAmountStr), 2)
|
||||||
@ -279,15 +272,14 @@ func (h *MenuHandlers) InitiatePayDebt(ctx context.Context, sym string, input []
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
swapAmount, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SWAP_AMOUNT)
|
swapData, err := store.ReadSwapPreviewData(ctx, userStore, sessionId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "failed to read swapAmount entry with", "key", storedb.DATA_ACTIVE_SWAP_AMOUNT, "error", err)
|
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
debtQuotedAmount, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
|
swapAmount, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SWAP_AMOUNT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "failed to read debtQuotedAmount entry with", "key", storedb.DATA_TEMPORARY_VALUE, "error", err)
|
logg.ErrorCtxf(ctx, "failed to read swapAmount entry with", "key", storedb.DATA_ACTIVE_SWAP_AMOUNT, "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +300,7 @@ func (h *MenuHandlers) InitiatePayDebt(ctx context.Context, sym string, input []
|
|||||||
|
|
||||||
res.Content = l.Get(
|
res.Content = l.Get(
|
||||||
"Your request has been sent. You will receive an SMS when your debt of %s %s has been removed from %s.",
|
"Your request has been sent. You will receive an SMS when your debt of %s %s has been removed from %s.",
|
||||||
string(debtQuotedAmount),
|
swapData.TemporaryValue,
|
||||||
string(activeSym),
|
string(activeSym),
|
||||||
activePoolName,
|
activePoolName,
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user