Compare commits
	
		
			No commits in common. "master" and "multi-pool" have entirely different histories.
		
	
	
		
			master
			...
			multi-pool
		
	
		
@ -7,56 +7,42 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	createAccountPath           = "/api/v2/account/create"
 | 
			
		||||
	trackStatusPath             = "/api/track"
 | 
			
		||||
	balancePathPrefix           = "/api/account"
 | 
			
		||||
	trackPath                   = "/api/v2/account/status"
 | 
			
		||||
	tokenTransferPrefix         = "/api/v2/token/transfer"
 | 
			
		||||
	voucherHoldingsPathPrefix   = "/api/v1/holdings"
 | 
			
		||||
	voucherTransfersPathPrefix  = "/api/v1/transfers/last10"
 | 
			
		||||
	voucherDataPathPrefix       = "/api/v1/token"
 | 
			
		||||
	SendSMSPrefix               = "api/v1/external/upsell"
 | 
			
		||||
	poolDepositPrefix           = "/api/v2/pool/deposit"
 | 
			
		||||
	poolSwapQoutePrefix         = "/api/v2/pool/quote"
 | 
			
		||||
	poolSwapPrefix              = "/api/v2/pool/swap"
 | 
			
		||||
	topPoolsPrefix              = "/api/v1/pool/top"
 | 
			
		||||
	retrievePoolDetailsPrefix   = "/api/v1/pool/reverse"
 | 
			
		||||
	poolSwappableVouchersPrefix = "/api/v1/pool"
 | 
			
		||||
	AliasRegistrationPrefix     = "/api/v1/internal/register"
 | 
			
		||||
	AliasResolverPrefix         = "/api/v1/resolve"
 | 
			
		||||
	ExternalSMSPrefix           = "/api/v1/external"
 | 
			
		||||
	AliasUpdatePrefix           = "/api/v1/internal/update"
 | 
			
		||||
	createAccountPath          = "/api/v2/account/create"
 | 
			
		||||
	trackStatusPath            = "/api/track"
 | 
			
		||||
	balancePathPrefix          = "/api/account"
 | 
			
		||||
	trackPath                  = "/api/v2/account/status"
 | 
			
		||||
	tokenTransferPrefix        = "/api/v2/token/transfer"
 | 
			
		||||
	voucherHoldingsPathPrefix  = "/api/v1/holdings"
 | 
			
		||||
	voucherTransfersPathPrefix = "/api/v1/transfers/last10"
 | 
			
		||||
	voucherDataPathPrefix      = "/api/v1/token"
 | 
			
		||||
	aliasPrefix                = "api/v1/alias"
 | 
			
		||||
	poolDepositPrefix          = "/api/v2/pool/deposit"
 | 
			
		||||
	poolSwapQoutePrefix        = "/api/v2/pool/quote"
 | 
			
		||||
	poolSwapPrefix             = "/api/v2/pool/swap"
 | 
			
		||||
	AliasEnsPrefix             = "/api/v1/bypass"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	custodialURLBase    string
 | 
			
		||||
	dataURLBase         string
 | 
			
		||||
	BearerToken         string
 | 
			
		||||
	aliasEnsURLBase     string
 | 
			
		||||
	externalSMSBase     string
 | 
			
		||||
	IncludeStablesParam string
 | 
			
		||||
	custodialURLBase string
 | 
			
		||||
	dataURLBase      string
 | 
			
		||||
	BearerToken      string
 | 
			
		||||
	aliasEnsURLBase  string
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	CreateAccountURL         string
 | 
			
		||||
	TrackStatusURL           string
 | 
			
		||||
	BalanceURL               string
 | 
			
		||||
	TrackURL                 string
 | 
			
		||||
	TokenTransferURL         string
 | 
			
		||||
	VoucherHoldingsURL       string
 | 
			
		||||
	VoucherTransfersURL      string
 | 
			
		||||
	VoucherDataURL           string
 | 
			
		||||
	PoolDepositURL           string
 | 
			
		||||
	PoolSwapQuoteURL         string
 | 
			
		||||
	PoolSwapURL              string
 | 
			
		||||
	TopPoolsURL              string
 | 
			
		||||
	RetrievePoolDetailsURL   string
 | 
			
		||||
	PoolSwappableVouchersURL string
 | 
			
		||||
	SendSMSURL               string
 | 
			
		||||
	AliasRegistrationURL     string
 | 
			
		||||
	AliasResolverURL         string
 | 
			
		||||
	ExternalSMSURL           string
 | 
			
		||||
	AliasUpdateURL           string
 | 
			
		||||
	CreateAccountURL    string
 | 
			
		||||
	TrackStatusURL      string
 | 
			
		||||
	BalanceURL          string
 | 
			
		||||
	TrackURL            string
 | 
			
		||||
	TokenTransferURL    string
 | 
			
		||||
	VoucherHoldingsURL  string
 | 
			
		||||
	VoucherTransfersURL string
 | 
			
		||||
	VoucherDataURL      string
 | 
			
		||||
	CheckAliasURL       string
 | 
			
		||||
	PoolDepositURL      string
 | 
			
		||||
	PoolSwapQuoteURL    string
 | 
			
		||||
	PoolSwapURL         string
 | 
			
		||||
	AliasEnsURL         string
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func setBase() error {
 | 
			
		||||
@ -65,9 +51,7 @@ func setBase() error {
 | 
			
		||||
	custodialURLBase = env.GetEnv("CUSTODIAL_URL_BASE", "http://localhost:5003")
 | 
			
		||||
	dataURLBase = env.GetEnv("DATA_URL_BASE", "http://localhost:5006")
 | 
			
		||||
	aliasEnsURLBase = env.GetEnv("ALIAS_ENS_BASE", "http://localhost:5015")
 | 
			
		||||
	externalSMSBase = env.GetEnv("EXTERNAL_SMS_BASE", "http://localhost:5035")
 | 
			
		||||
	BearerToken = env.GetEnv("BEARER_TOKEN", "")
 | 
			
		||||
	IncludeStablesParam = env.GetEnv("INCLUDE_STABLES_PARAM", "false")
 | 
			
		||||
 | 
			
		||||
	_, err = url.Parse(custodialURLBase)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@ -94,17 +78,11 @@ func LoadConfig() error {
 | 
			
		||||
	VoucherHoldingsURL, _ = url.JoinPath(dataURLBase, voucherHoldingsPathPrefix)
 | 
			
		||||
	VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix)
 | 
			
		||||
	VoucherDataURL, _ = url.JoinPath(dataURLBase, voucherDataPathPrefix)
 | 
			
		||||
	SendSMSURL, _ = url.JoinPath(dataURLBase, SendSMSPrefix)
 | 
			
		||||
	CheckAliasURL, _ = url.JoinPath(dataURLBase, aliasPrefix)
 | 
			
		||||
	PoolDepositURL, _ = url.JoinPath(custodialURLBase, poolDepositPrefix)
 | 
			
		||||
	PoolSwapQuoteURL, _ = url.JoinPath(custodialURLBase, poolSwapQoutePrefix)
 | 
			
		||||
	PoolSwapURL, _ = url.JoinPath(custodialURLBase, poolSwapPrefix)
 | 
			
		||||
	TopPoolsURL, _ = url.JoinPath(dataURLBase, topPoolsPrefix)
 | 
			
		||||
	RetrievePoolDetailsURL, _ = url.JoinPath(dataURLBase, retrievePoolDetailsPrefix)
 | 
			
		||||
	PoolSwappableVouchersURL, _ = url.JoinPath(dataURLBase, poolSwappableVouchersPrefix)
 | 
			
		||||
	AliasRegistrationURL, _ = url.JoinPath(aliasEnsURLBase, AliasRegistrationPrefix)
 | 
			
		||||
	AliasResolverURL, _ = url.JoinPath(aliasEnsURLBase, AliasResolverPrefix)
 | 
			
		||||
	ExternalSMSURL, _ = url.JoinPath(externalSMSBase, ExternalSMSPrefix)
 | 
			
		||||
	AliasUpdateURL, _ = url.JoinPath(aliasEnsURLBase, AliasUpdatePrefix)
 | 
			
		||||
 | 
			
		||||
	AliasEnsURL, _ = url.JoinPath(aliasEnsURLBase, AliasEnsPrefix)
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										55
									
								
								dev/api.go
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								dev/api.go
									
									
									
									
									
								
							@ -233,6 +233,7 @@ func (das *DevAccountService) loadItem(ctx context.Context, k []byte, v []byte)
 | 
			
		||||
	if len(ss) != 2 {
 | 
			
		||||
		return fmt.Errorf("malformed key: %s", s)
 | 
			
		||||
	}
 | 
			
		||||
	fmt.Println("S1", ss[0])
 | 
			
		||||
	if ss[0] == "account" {
 | 
			
		||||
		err = das.loadAccount(ctx, ss[1], v)
 | 
			
		||||
		logg.ErrorCtxf(ctx, "loading saved account failed", "error_load_account", err)
 | 
			
		||||
@ -587,7 +588,7 @@ func (das *DevAccountService) FetchVouchers(ctx context.Context, publicKey strin
 | 
			
		||||
	//TODO: Iterate over the account acc.Balances object
 | 
			
		||||
	for _, voucher := range das.vouchers {
 | 
			
		||||
		holdings = append(holdings, dataserviceapi.TokenHoldings{
 | 
			
		||||
			TokenAddress: voucher.Address,
 | 
			
		||||
			ContractAddress: voucher.Address,
 | 
			
		||||
			TokenSymbol:     voucher.Symbol,
 | 
			
		||||
			TokenDecimals:   strconv.Itoa(voucher.Decimals),
 | 
			
		||||
			Balance:         strconv.Itoa(int(defaultVoucherBalance)),
 | 
			
		||||
@ -806,28 +807,6 @@ func (das *DevAccountService) RequestAlias(ctx context.Context, publicKey string
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (das *DevAccountService) UpdateAlias(ctx context.Context, publicKey string, name string) (*models.RequestAliasResult, error) {
 | 
			
		||||
	logg.DebugCtxf(ctx, "Updated the alias", "address", publicKey, "name", name)
 | 
			
		||||
	return &models.RequestAliasResult{
 | 
			
		||||
		Alias: name,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (das *DevAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
 | 
			
		||||
	logg.DebugCtxf(ctx, "sent an SMS", "inviterPhone", inviterPhone, "inviteePhone", inviteePhone)
 | 
			
		||||
	return &models.SendSMSResponse{
 | 
			
		||||
		Invitee: inviteePhone,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (das *DevAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error {
 | 
			
		||||
	return fmt.Errorf("unimplemented")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (das *DevAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error {
 | 
			
		||||
	return fmt.Errorf("unimplemented")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (das *DevAccountService) FetchTopPools(ctx context.Context) ([]dataserviceapi.PoolDetails, error) {
 | 
			
		||||
	var topPools []dataserviceapi.PoolDetails
 | 
			
		||||
	for _, p := range das.pools {
 | 
			
		||||
@ -840,18 +819,6 @@ func (das *DevAccountService) FetchTopPools(ctx context.Context) ([]dataservicea
 | 
			
		||||
	return topPools, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (das *DevAccountService) RetrievePoolDetails(ctx context.Context, sym string) (*dataserviceapi.PoolDetails, error) {
 | 
			
		||||
	testPool := &dataserviceapi.PoolDetails{
 | 
			
		||||
		PoolName:            "DevTest",
 | 
			
		||||
		PoolSymbol:          "DEVT",
 | 
			
		||||
		PoolContractAdrress: "0x145F87d6198dEDD45C614FFD8b70E9a2fCCc5cc9",
 | 
			
		||||
		LimiterAddress:      "",
 | 
			
		||||
		VoucherRegistry:     "",
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return testPool, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (das *DevAccountService) GetPoolSwappableFromVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	var swapFromList []dataserviceapi.TokenHoldings
 | 
			
		||||
 | 
			
		||||
@ -861,7 +828,7 @@ func (das *DevAccountService) GetPoolSwappableFromVouchers(ctx context.Context,
 | 
			
		||||
	}
 | 
			
		||||
	for _, v := range p.Vouchers {
 | 
			
		||||
		swapFromList = append(swapFromList, dataserviceapi.TokenHoldings{
 | 
			
		||||
			TokenAddress: v.Address,
 | 
			
		||||
			ContractAddress: v.Address,
 | 
			
		||||
			TokenSymbol:     v.Symbol,
 | 
			
		||||
			TokenDecimals:   string(defaultDecimals),
 | 
			
		||||
			Balance:         fmt.Sprintf("%f", defaultVoucherBalance),
 | 
			
		||||
@ -871,7 +838,7 @@ func (das *DevAccountService) GetPoolSwappableFromVouchers(ctx context.Context,
 | 
			
		||||
	return swapFromList, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (das *DevAccountService) GetPoolSwappableVouchers(ctx context.Context, poolAddress string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
func (das *DevAccountService) GetPoolSwappableVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	var swapToList []dataserviceapi.TokenHoldings
 | 
			
		||||
	_, ok := das.pools[poolAddress]
 | 
			
		||||
	if !ok {
 | 
			
		||||
@ -879,15 +846,17 @@ func (das *DevAccountService) GetPoolSwappableVouchers(ctx context.Context, pool
 | 
			
		||||
	}
 | 
			
		||||
	for _, voucher := range das.vouchers {
 | 
			
		||||
		swapToList = append(swapToList, dataserviceapi.TokenHoldings{
 | 
			
		||||
			TokenAddress:  voucher.Address,
 | 
			
		||||
			TokenSymbol:   voucher.Symbol,
 | 
			
		||||
			TokenDecimals: strconv.Itoa(voucher.Decimals),
 | 
			
		||||
			ContractAddress: voucher.Address,
 | 
			
		||||
			TokenSymbol:     voucher.Symbol,
 | 
			
		||||
			TokenDecimals:   string(defaultDecimals),
 | 
			
		||||
			Balance:         fmt.Sprintf("%f", defaultVoucherBalance),
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	return swapToList, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (das *DevAccountService) GetSwapFromTokenMaxLimit(ctx context.Context, poolAddress, fromTokenAddress, toTokenAddress, publicKey string) (*models.MaxLimitResult, error) {
 | 
			
		||||
 | 
			
		||||
	p, ok := das.pools[poolAddress]
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return nil, fmt.Errorf("Pool address: %v not found ", poolAddress)
 | 
			
		||||
@ -901,9 +870,3 @@ func (das *DevAccountService) GetSwapFromTokenMaxLimit(ctx context.Context, pool
 | 
			
		||||
		Max: limit,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (das *DevAccountService) CheckTokenInPool(ctx context.Context, poolAddress, tokenAddress string) (*models.TokenInPoolResult, error) {
 | 
			
		||||
	return &models.TokenInPoolResult{
 | 
			
		||||
		CanSwapFrom: true,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							@ -8,7 +8,7 @@ require (
 | 
			
		||||
	git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250122123424-6749c632b0a2
 | 
			
		||||
	github.com/gofrs/uuid v4.4.0+incompatible
 | 
			
		||||
	github.com/grassrootseconomics/eth-custodial v1.3.0-beta
 | 
			
		||||
	github.com/grassrootseconomics/ussd-data-service v1.6.0-beta
 | 
			
		||||
	github.com/grassrootseconomics/ussd-data-service v1.4.0-beta
 | 
			
		||||
	github.com/stretchr/testify v1.9.0
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										8
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								go.sum
									
									
									
									
									
								
							@ -20,14 +20,6 @@ github.com/grassrootseconomics/ussd-data-service v1.2.0-beta h1:fn1gwbWIwHVEBtUC
 | 
			
		||||
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta/go.mod h1:omfI0QtUwIdpu9gMcUqLMCG8O1XWjqJGBx1qUMiGWC0=
 | 
			
		||||
github.com/grassrootseconomics/ussd-data-service v1.4.0-beta h1:4fMd/3h2ZIhRg4GdHQmRw5FfD3MpJvFNNJQo+Q27f5M=
 | 
			
		||||
github.com/grassrootseconomics/ussd-data-service v1.4.0-beta/go.mod h1:9sGnorpKaK76FmOGXoh/xv7x5siSFNYdXxQo9BKW4DI=
 | 
			
		||||
github.com/grassrootseconomics/ussd-data-service v1.4.4-beta h1:turlyo0i3OLj29mWpWNoB/3Qao8qEngT/5d1jDWTZE4=
 | 
			
		||||
github.com/grassrootseconomics/ussd-data-service v1.4.4-beta/go.mod h1:9sGnorpKaK76FmOGXoh/xv7x5siSFNYdXxQo9BKW4DI=
 | 
			
		||||
github.com/grassrootseconomics/ussd-data-service v1.4.7-beta h1:yAe1YaOBsdxW2m20jnVU4F0kLmFr+mK/gHCWEdHmE90=
 | 
			
		||||
github.com/grassrootseconomics/ussd-data-service v1.4.7-beta/go.mod h1:9sGnorpKaK76FmOGXoh/xv7x5siSFNYdXxQo9BKW4DI=
 | 
			
		||||
github.com/grassrootseconomics/ussd-data-service v1.5.0-beta h1:BSSQL/yPEvTVku9ja/ENZyZdwZkEaiTzzOUfg72bTy4=
 | 
			
		||||
github.com/grassrootseconomics/ussd-data-service v1.5.0-beta/go.mod h1:9sGnorpKaK76FmOGXoh/xv7x5siSFNYdXxQo9BKW4DI=
 | 
			
		||||
github.com/grassrootseconomics/ussd-data-service v1.6.0-beta h1:pY6zns6ifXyClRxP+JJaWrged3oRE7tTS2xaftF9clA=
 | 
			
		||||
github.com/grassrootseconomics/ussd-data-service v1.6.0-beta/go.mod h1:9sGnorpKaK76FmOGXoh/xv7x5siSFNYdXxQo9BKW4DI=
 | 
			
		||||
github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4 h1:U4kkNYryi/qfbBF8gh7Vsbuz+cVmhf5kt6pE9bYYyLo=
 | 
			
		||||
github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4/go.mod h1:zpZDgZFzeq9s0MIeB1P50NIEWDFFHSFBohI/NbaTD/Y=
 | 
			
		||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,3 @@ type PoolSwapResult struct {
 | 
			
		||||
type MaxLimitResult struct {
 | 
			
		||||
	Max string `json:"max"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type TokenInPoolResult struct {
 | 
			
		||||
	CanSwapFrom bool `json:"canSwapFrom"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,5 +0,0 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
type SendSMSResponse struct {
 | 
			
		||||
	Invitee string `json:"invitee"`
 | 
			
		||||
}
 | 
			
		||||
@ -17,17 +17,11 @@ type AccountService interface {
 | 
			
		||||
	TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error)
 | 
			
		||||
	CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error)
 | 
			
		||||
	RequestAlias(ctx context.Context, hint string, publicKey string) (*models.RequestAliasResult, error)
 | 
			
		||||
	UpdateAlias(ctx context.Context, name string, publicKey string) (*models.RequestAliasResult, error)
 | 
			
		||||
	SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error)
 | 
			
		||||
	SendAddressSMS(ctx context.Context, publicKey, originPhone string) error
 | 
			
		||||
	SendPINResetSMS(ctx context.Context, admin, phone string) error
 | 
			
		||||
	PoolDeposit(ctx context.Context, amount, from, poolAddress, tokenAddress string) (*models.PoolDepositResult, error)
 | 
			
		||||
	FetchTopPools(ctx context.Context) ([]dataserviceapi.PoolDetails, error)
 | 
			
		||||
	RetrievePoolDetails(ctx context.Context, sym string) (*dataserviceapi.PoolDetails, error)
 | 
			
		||||
	GetPoolSwappableFromVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error)
 | 
			
		||||
	GetPoolSwappableVouchers(ctx context.Context, poolAddress string) ([]dataserviceapi.TokenHoldings, error)
 | 
			
		||||
	GetPoolSwappableVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error)
 | 
			
		||||
	GetPoolSwapQuote(ctx context.Context, amount, from, fromTokenAddress, poolAddress, toTokenAddress string) (*models.PoolSwapQuoteResult, error)
 | 
			
		||||
	PoolSwap(ctx context.Context, amount, from, fromTokenAddress, poolAddress, toTokenAddress string) (*models.PoolSwapResult, error)
 | 
			
		||||
	GetSwapFromTokenMaxLimit(ctx context.Context, poolAddress, fromTokenAddress, toTokenAddress, publicKey string) (*models.MaxLimitResult, error)
 | 
			
		||||
	CheckTokenInPool(ctx context.Context, poolAddress, tokenAddress string) (*models.TokenInPoolResult, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -27,36 +27,11 @@ var (
 | 
			
		||||
	logg       = logging.NewVanilla().WithDomain("sarafu-api.devapi")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type APIError struct {
 | 
			
		||||
	Code        string
 | 
			
		||||
	Description string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (e *APIError) Error() string {
 | 
			
		||||
	if e.Code != "" {
 | 
			
		||||
		return fmt.Sprintf("[%s] %s", e.Code, e.Description)
 | 
			
		||||
	}
 | 
			
		||||
	return e.Description
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type HTTPAccountService struct {
 | 
			
		||||
	SS     storage.StorageService
 | 
			
		||||
	UseApi bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// symbolReplacements holds mappings of invalid symbols → valid ones
 | 
			
		||||
var symbolReplacements = map[string]string{
 | 
			
		||||
	"USD₮": "USDT",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// sanitizeSymbol replaces known invalid token symbols with normalized ones
 | 
			
		||||
func sanitizeSymbol(symbol string) string {
 | 
			
		||||
	if replacement, ok := symbolReplacements[symbol]; ok {
 | 
			
		||||
		return replacement
 | 
			
		||||
	}
 | 
			
		||||
	return symbol
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Parameters:
 | 
			
		||||
//   - trackingId: A unique identifier for the account.This should be obtained from a previous call to
 | 
			
		||||
//     CreateAccount or a similar function that returns an AccountResponse. The `trackingId` field in the
 | 
			
		||||
@ -155,11 +130,6 @@ func (as *HTTPAccountService) FetchVouchers(ctx context.Context, publicKey strin
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Normalize symbols before returning
 | 
			
		||||
	for i := range r.Holdings {
 | 
			
		||||
		r.Holdings[i].TokenSymbol = sanitizeSymbol(r.Holdings[i].TokenSymbol)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return r.Holdings, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -186,11 +156,6 @@ func (as *HTTPAccountService) FetchTransactions(ctx context.Context, publicKey s
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Normalize symbols before returning
 | 
			
		||||
	for i := range r.Transfers {
 | 
			
		||||
		r.Transfers[i].TokenSymbol = sanitizeSymbol(r.Transfers[i].TokenSymbol)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return r.Transfers, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -212,9 +177,6 @@ func (as *HTTPAccountService) VoucherData(ctx context.Context, address string) (
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Normalize symbols before returning
 | 
			
		||||
	r.TokenDetails.TokenSymbol = sanitizeSymbol(r.TokenDetails.TokenSymbol)
 | 
			
		||||
 | 
			
		||||
	_, err = doRequest(ctx, req, &r)
 | 
			
		||||
	return &r.TokenDetails, err
 | 
			
		||||
}
 | 
			
		||||
@ -272,76 +234,38 @@ func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias strin
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func resolveAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
 | 
			
		||||
	var aliasEnsResult models.AliasEnsAddressResult
 | 
			
		||||
	var (
 | 
			
		||||
		aliasEnsResult models.AliasEnsAddressResult
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	fullURL, err := url.JoinPath(config.AliasResolverURL, alias)
 | 
			
		||||
	ep, err := url.JoinPath(config.AliasEnsURL, "/resolve")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	req, err := http.NewRequest("GET", fullURL, nil)
 | 
			
		||||
	u, err := url.Parse(ep)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	query := u.Query()
 | 
			
		||||
	query.Set("name", alias)
 | 
			
		||||
	u.RawQuery = query.Encode()
 | 
			
		||||
 | 
			
		||||
	req, err := http.NewRequest("GET", u.String(), nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	_, err = doRequest(ctx, req, &aliasEnsResult)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &models.AliasAddress{Address: aliasEnsResult.Address}, nil
 | 
			
		||||
	return &models.AliasAddress{Address: aliasEnsResult.Address}, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) FetchTopPools(ctx context.Context) ([]dataserviceapi.PoolDetails, error) {
 | 
			
		||||
	svc := dev.NewDevAccountService(ctx, as.SS)
 | 
			
		||||
	if as.UseApi {
 | 
			
		||||
		return fetchCustodialTopPools(ctx)
 | 
			
		||||
	} else {
 | 
			
		||||
		return svc.FetchTopPools(ctx)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func fetchCustodialTopPools(ctx context.Context) ([]dataserviceapi.PoolDetails, error) {
 | 
			
		||||
	var r struct {
 | 
			
		||||
		TopPools []dataserviceapi.PoolDetails `json:"topPools"`
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	req, err := http.NewRequest("GET", config.TopPoolsURL, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = doRequest(ctx, req, &r)
 | 
			
		||||
	return r.TopPools, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) RetrievePoolDetails(ctx context.Context, sym string) (*dataserviceapi.PoolDetails, error) {
 | 
			
		||||
	if as.UseApi {
 | 
			
		||||
		return retrievePoolDetails(ctx, sym)
 | 
			
		||||
	} else {
 | 
			
		||||
		return nil, nil
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func retrievePoolDetails(ctx context.Context, sym string) (*dataserviceapi.PoolDetails, error) {
 | 
			
		||||
	var r struct {
 | 
			
		||||
		PoolDetails dataserviceapi.PoolDetails `json:"poolDetails"`
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ep, err := url.JoinPath(config.RetrievePoolDetailsURL, sym)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	req, err := http.NewRequest("GET", ep, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	_, err = doRequest(ctx, req, &r)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &r.PoolDetails, nil
 | 
			
		||||
	return svc.FetchTopPools(ctx)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) PoolDeposit(ctx context.Context, amount, from, poolAddress, tokenAddress string) (*models.PoolDepositResult, error) {
 | 
			
		||||
@ -386,7 +310,6 @@ func (as *HTTPAccountService) GetPoolSwapQuote(ctx context.Context, amount, from
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	req, err := http.NewRequest("POST", config.PoolSwapQuoteURL, bytes.NewBuffer(payloadBytes))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@ -399,85 +322,13 @@ func (as *HTTPAccountService) GetPoolSwapQuote(ctx context.Context, amount, from
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) GetPoolSwappableFromVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	if as.UseApi {
 | 
			
		||||
		return as.getPoolSwappableFromVouchers(ctx, poolAddress, publicKey)
 | 
			
		||||
	} else {
 | 
			
		||||
		svc := dev.NewDevAccountService(ctx, as.SS)
 | 
			
		||||
		return svc.GetPoolSwappableFromVouchers(ctx, poolAddress, publicKey)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) getPoolSwappableFromVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	var r struct {
 | 
			
		||||
		PoolSwappableVouchers []dataserviceapi.TokenHoldings `json:"filtered"`
 | 
			
		||||
	}
 | 
			
		||||
	ep, err := url.JoinPath(config.PoolSwappableVouchersURL, poolAddress, "from", publicKey)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	req, err := http.NewRequest("GET", ep, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	_, err = doRequest(ctx, req, &r)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Normalize symbols before returning
 | 
			
		||||
	for i := range r.PoolSwappableVouchers {
 | 
			
		||||
		r.PoolSwappableVouchers[i].TokenSymbol = sanitizeSymbol(r.PoolSwappableVouchers[i].TokenSymbol)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return r.PoolSwappableVouchers, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) GetPoolSwappableVouchers(ctx context.Context, poolAddress string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	svc := dev.NewDevAccountService(ctx, as.SS)
 | 
			
		||||
	if as.UseApi {
 | 
			
		||||
		return as.getPoolSwappableVouchers(ctx, poolAddress)
 | 
			
		||||
	} else {
 | 
			
		||||
		return svc.GetPoolSwappableVouchers(ctx, poolAddress)
 | 
			
		||||
	}
 | 
			
		||||
	return svc.GetPoolSwappableFromVouchers(ctx, poolAddress, publicKey)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as HTTPAccountService) getPoolSwappableVouchers(ctx context.Context, poolAddress string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	var r struct {
 | 
			
		||||
		PoolSwappableVouchers []dataserviceapi.TokenHoldings `json:"filtered"`
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	basePath, err := url.JoinPath(config.PoolSwappableVouchersURL, poolAddress, "to")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	parsedURL, err := url.Parse(basePath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	query := parsedURL.Query()
 | 
			
		||||
	if config.IncludeStablesParam != "" {
 | 
			
		||||
		query.Set("stables", config.IncludeStablesParam)
 | 
			
		||||
	}
 | 
			
		||||
	parsedURL.RawQuery = query.Encode()
 | 
			
		||||
 | 
			
		||||
	req, err := http.NewRequest("GET", parsedURL.String(), nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = doRequest(ctx, req, &r)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Normalize symbols before returning
 | 
			
		||||
	for i := range r.PoolSwappableVouchers {
 | 
			
		||||
		r.PoolSwappableVouchers[i].TokenSymbol = sanitizeSymbol(r.PoolSwappableVouchers[i].TokenSymbol)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return r.PoolSwappableVouchers, nil
 | 
			
		||||
func (as *HTTPAccountService) GetPoolSwappableVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	svc := dev.NewDevAccountService(ctx, as.SS)
 | 
			
		||||
	return svc.GetPoolSwappableVouchers(ctx, poolAddress, publicKey)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) PoolSwap(ctx context.Context, amount, from, fromTokenAddress, poolAddress, toTokenAddress string) (*models.PoolSwapResult, error) {
 | 
			
		||||
@ -496,8 +347,7 @@ func (as *HTTPAccountService) PoolSwap(ctx context.Context, amount, from, fromTo
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	req, err := http.NewRequest("POST", config.PoolSwapURL, bytes.NewBuffer(payloadBytes))
 | 
			
		||||
	req, err := http.NewRequest("POST", config.PoolSwapQuoteURL, bytes.NewBuffer(payloadBytes))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
@ -509,62 +359,10 @@ func (as *HTTPAccountService) PoolSwap(ctx context.Context, amount, from, fromTo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) GetSwapFromTokenMaxLimit(ctx context.Context, poolAddress, fromTokenAddress, toTokenAddress, publicKey string) (*models.MaxLimitResult, error) {
 | 
			
		||||
	if as.UseApi {
 | 
			
		||||
		return as.getSwapFromTokenMaxLimit(ctx, poolAddress, fromTokenAddress, toTokenAddress, publicKey)
 | 
			
		||||
	} else {
 | 
			
		||||
		svc := dev.NewDevAccountService(ctx, as.SS)
 | 
			
		||||
		return svc.GetSwapFromTokenMaxLimit(ctx, poolAddress, fromTokenAddress, toTokenAddress, publicKey)
 | 
			
		||||
	}
 | 
			
		||||
	svc := dev.NewDevAccountService(ctx, as.SS)
 | 
			
		||||
	return svc.GetSwapFromTokenMaxLimit(ctx, poolAddress, fromTokenAddress, toTokenAddress, publicKey)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) getSwapFromTokenMaxLimit(ctx context.Context, poolAddress, fromTokenAddress, toTokeAddress, publicKey string) (*models.MaxLimitResult, error) {
 | 
			
		||||
	var r models.MaxLimitResult
 | 
			
		||||
 | 
			
		||||
	ep, err := url.JoinPath(config.PoolSwappableVouchersURL, poolAddress, "limit", fromTokenAddress, toTokeAddress, publicKey)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	req, err := http.NewRequest("GET", ep, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	_, err = doRequest(ctx, req, &r)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &r, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) CheckTokenInPool(ctx context.Context, poolAddress, tokenAddress string) (*models.TokenInPoolResult, error) {
 | 
			
		||||
	if as.UseApi {
 | 
			
		||||
		return as.checkTokenInPool(ctx, poolAddress, tokenAddress)
 | 
			
		||||
	} else {
 | 
			
		||||
		svc := dev.NewDevAccountService(ctx, as.SS)
 | 
			
		||||
		return svc.CheckTokenInPool(ctx, poolAddress, tokenAddress)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) checkTokenInPool(ctx context.Context, poolAddress, tokenAddress string) (*models.TokenInPoolResult, error) {
 | 
			
		||||
	var r models.TokenInPoolResult
 | 
			
		||||
 | 
			
		||||
	ep, err := url.JoinPath(config.PoolSwappableVouchersURL, poolAddress, "check", tokenAddress)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	req, err := http.NewRequest("GET", ep, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	_, err = doRequest(ctx, req, &r)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &r, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO: Use actual custodial api to request available alias
 | 
			
		||||
func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
 | 
			
		||||
	if as.SS == nil {
 | 
			
		||||
		return nil, fmt.Errorf("The storage service cannot be nil")
 | 
			
		||||
@ -587,9 +385,11 @@ func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string
 | 
			
		||||
func requestEnsAlias(ctx context.Context, publicKey string, hint string) (*models.AliasEnsResult, error) {
 | 
			
		||||
	var r models.AliasEnsResult
 | 
			
		||||
 | 
			
		||||
	endpoint := config.AliasRegistrationURL
 | 
			
		||||
 | 
			
		||||
	logg.InfoCtxf(ctx, "requesting alias", "endpoint", endpoint, "hint", hint)
 | 
			
		||||
	ep, err := url.JoinPath(config.AliasEnsURL, "/register")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	logg.InfoCtxf(ctx, "requesting alias", "endpoint", ep, "hint", hint)
 | 
			
		||||
	//Payload with the address and hint to derive an ENS name
 | 
			
		||||
	payload := map[string]string{
 | 
			
		||||
		"address": publicKey,
 | 
			
		||||
@ -599,7 +399,7 @@ func requestEnsAlias(ctx context.Context, publicKey string, hint string) (*model
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(payloadBytes))
 | 
			
		||||
	req, err := http.NewRequest("POST", ep, bytes.NewBuffer(payloadBytes))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
@ -613,135 +413,6 @@ func requestEnsAlias(ctx context.Context, publicKey string, hint string) (*model
 | 
			
		||||
	return &r, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) UpdateAlias(ctx context.Context, name string, publicKey string) (*models.RequestAliasResult, error) {
 | 
			
		||||
	if as.SS == nil {
 | 
			
		||||
		return nil, fmt.Errorf("The storage service cannot be nil")
 | 
			
		||||
	}
 | 
			
		||||
	if as.UseApi {
 | 
			
		||||
		if !strings.Contains(name, ".") {
 | 
			
		||||
			name = as.ToFqdn(name)
 | 
			
		||||
		}
 | 
			
		||||
		enr, err := updateEnsAlias(ctx, name, publicKey)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		return &models.RequestAliasResult{Alias: enr.Name}, nil
 | 
			
		||||
	} else {
 | 
			
		||||
		svc := dev.NewDevAccountService(ctx, as.SS)
 | 
			
		||||
		return svc.RequestAlias(ctx, publicKey, name)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func updateEnsAlias(ctx context.Context, name string, publicKey string) (*models.AliasEnsResult, error) {
 | 
			
		||||
	var r models.AliasEnsResult
 | 
			
		||||
 | 
			
		||||
	endpoint := config.AliasUpdateURL
 | 
			
		||||
 | 
			
		||||
	logg.InfoCtxf(ctx, "updating alias", "endpoint", endpoint, "name", name)
 | 
			
		||||
 | 
			
		||||
	payload := map[string]string{
 | 
			
		||||
		"name":    name,
 | 
			
		||||
		"address": publicKey,
 | 
			
		||||
	}
 | 
			
		||||
	payloadBytes, err := json.Marshal(payload)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	req, err := http.NewRequest("PUT", endpoint, bytes.NewBuffer(payloadBytes))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	// Log the request body
 | 
			
		||||
	logg.InfoCtxf(ctx, "request body", "payload", string(payloadBytes))
 | 
			
		||||
	_, err = doRequest(ctx, req, &r)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	logg.InfoCtxf(ctx, "alias successfully updated", "alias", r.Name)
 | 
			
		||||
	return &r, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SendSMS calls the API to send out an SMS.
 | 
			
		||||
// Parameters:
 | 
			
		||||
//   - inviterPhone: The user initiating the SMS.
 | 
			
		||||
//   - inviteePhone: The number being invited to Sarafu.
 | 
			
		||||
func (as *HTTPAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
 | 
			
		||||
	var r models.SendSMSResponse
 | 
			
		||||
 | 
			
		||||
	// Create request payload
 | 
			
		||||
	payload := map[string]string{
 | 
			
		||||
		"inviterPhone": inviterPhone,
 | 
			
		||||
		"inviteePhone": inviteePhone,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	payloadBytes, err := json.Marshal(payload)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Create a new request
 | 
			
		||||
	req, err := http.NewRequest("POST", config.SendSMSURL, bytes.NewBuffer(payloadBytes))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	_, err = doRequest(ctx, req, &r)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &r, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error {
 | 
			
		||||
	ep, err := url.JoinPath(config.ExternalSMSURL, "address")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	logg.InfoCtxf(ctx, "sending an address sms", "endpoint", ep, "address", publicKey, "origin-phone", originPhone)
 | 
			
		||||
	payload := map[string]string{
 | 
			
		||||
		"address":     publicKey,
 | 
			
		||||
		"originPhone": originPhone,
 | 
			
		||||
	}
 | 
			
		||||
	payloadBytes, err := json.Marshal(payload)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	req, err := http.NewRequest("POST", ep, bytes.NewBuffer(payloadBytes))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	_, err = doRequest(ctx, req, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (as *HTTPAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error {
 | 
			
		||||
	ep, err := url.JoinPath(config.ExternalSMSURL, "pinreset")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	logg.InfoCtxf(ctx, "sending pin reset sms", "endpoint", ep, "admin", admin, "phone", phone)
 | 
			
		||||
	payload := map[string]string{
 | 
			
		||||
		"admin": admin,
 | 
			
		||||
		"phone": phone,
 | 
			
		||||
	}
 | 
			
		||||
	payloadBytes, err := json.Marshal(payload)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	req, err := http.NewRequest("POST", ep, bytes.NewBuffer(payloadBytes))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	_, err = doRequest(ctx, req, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO: remove eth-custodial api dependency
 | 
			
		||||
func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
 | 
			
		||||
	var okResponse api.OKResponse
 | 
			
		||||
@ -750,7 +421,6 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
 | 
			
		||||
	req.Header.Set("Authorization", "Bearer "+config.BearerToken)
 | 
			
		||||
	req.Header.Set("Content-Type", "application/json")
 | 
			
		||||
 | 
			
		||||
	// Log request
 | 
			
		||||
	logRequestDetails(req)
 | 
			
		||||
 | 
			
		||||
	resp, err := http.DefaultClient.Do(req)
 | 
			
		||||
@ -761,32 +431,24 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
 | 
			
		||||
	}
 | 
			
		||||
	defer resp.Body.Close()
 | 
			
		||||
 | 
			
		||||
	// Read and log response body
 | 
			
		||||
	log.Printf("Received response for %s: Status Code: %d | Content-Type: %s", req.URL, resp.StatusCode, resp.Header.Get("Content-Type"))
 | 
			
		||||
	body, err := io.ReadAll(resp.Body)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	log.Printf("Received response for %s: Status Code: %d | Content-Type: %s | Body: %s",
 | 
			
		||||
		req.URL, resp.StatusCode, resp.Header.Get("Content-Type"), string(body))
 | 
			
		||||
 | 
			
		||||
	if resp.StatusCode >= http.StatusBadRequest {
 | 
			
		||||
		if err := json.Unmarshal(body, &errResponse); err != nil {
 | 
			
		||||
		err := json.Unmarshal([]byte(body), &errResponse)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return nil, &APIError{
 | 
			
		||||
			Code:        errResponse.ErrCode,
 | 
			
		||||
			Description: errResponse.Description,
 | 
			
		||||
		}
 | 
			
		||||
		return nil, errors.New(errResponse.Description)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := json.Unmarshal(body, &okResponse); err != nil {
 | 
			
		||||
	err = json.Unmarshal([]byte(body), &okResponse)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(okResponse.Result) == 0 {
 | 
			
		||||
		return nil, errors.New("empty api result")
 | 
			
		||||
		return nil, errors.New("Empty api result")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	v, err := json.Marshal(okResponse.Result)
 | 
			
		||||
@ -801,14 +463,16 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
 | 
			
		||||
func logRequestDetails(req *http.Request) {
 | 
			
		||||
	var bodyBytes []byte
 | 
			
		||||
	contentType := req.Header.Get("Content-Type")
 | 
			
		||||
 | 
			
		||||
	if req.Body != nil {
 | 
			
		||||
		bodyBytes, _ = io.ReadAll(req.Body)
 | 
			
		||||
		req.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) // Restore body
 | 
			
		||||
		bodyBytes, err := io.ReadAll(req.Body)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Printf("Error reading request body: %s", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		req.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
 | 
			
		||||
	} else {
 | 
			
		||||
		bodyBytes = []byte("-")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	log.Printf("Outgoing Request -> URL: %s | Method: %s | Content-Type: %s | Body: %s",
 | 
			
		||||
		req.URL.String(), req.Method, contentType, string(bodyBytes))
 | 
			
		||||
	log.Printf("URL: %s | Content-Type: %s | Method: %s| Request Body: %s", req.URL, contentType, req.Method, string(bodyBytes))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -58,14 +58,6 @@ func (m MockApi) RequestAlias(ctx context.Context, publicKey string, hint string
 | 
			
		||||
	return nil, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m MockApi) UpdateAlias(ctx context.Context, publicKey string, name string) (*models.RequestAliasResult, error) {
 | 
			
		||||
	return nil, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m MockApi) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) {
 | 
			
		||||
	return nil, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m MockApi) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
 | 
			
		||||
	return nil, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -53,29 +53,11 @@ func (m *MockAccountService) CheckAliasAddress(ctx context.Context, alias string
 | 
			
		||||
	return args.Get(0).(*models.AliasAddress), args.Error(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *MockAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
 | 
			
		||||
func (m MockAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
 | 
			
		||||
	args := m.Called(publicKey, hint)
 | 
			
		||||
	return args.Get(0).(*models.RequestAliasResult), args.Error(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *MockAccountService) UpdateAlias(ctx context.Context, publicKey string, name string) (*models.RequestAliasResult, error) {
 | 
			
		||||
	args := m.Called(publicKey, name)
 | 
			
		||||
	return args.Get(0).(*models.RequestAliasResult), args.Error(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *MockAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
 | 
			
		||||
	args := m.Called(inviterPhone, inviteePhone)
 | 
			
		||||
	return args.Get(0).(*models.SendSMSResponse), args.Error(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *MockAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *MockAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m MockAccountService) PoolDeposit(ctx context.Context, amount, from, poolAddress, tokenAddress string) (*models.PoolDepositResult, error) {
 | 
			
		||||
	args := m.Called(amount, from, poolAddress, tokenAddress)
 | 
			
		||||
	return args.Get(0).(*models.PoolDepositResult), args.Error(1)
 | 
			
		||||
@ -86,18 +68,13 @@ func (m MockAccountService) FetchTopPools(ctx context.Context) ([]dataserviceapi
 | 
			
		||||
	return args.Get(0).([]dataserviceapi.PoolDetails), args.Error(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m MockAccountService) RetrievePoolDetails(ctx context.Context, sym string) (*dataserviceapi.PoolDetails, error) {
 | 
			
		||||
	args := m.Called()
 | 
			
		||||
	return args.Get(0).(*dataserviceapi.PoolDetails), args.Error(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m MockAccountService) GetPoolSwappableFromVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	args := m.Called(poolAddress, publicKey)
 | 
			
		||||
	return args.Get(0).([]dataserviceapi.TokenHoldings), args.Error(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m MockAccountService) GetPoolSwappableVouchers(ctx context.Context, poolAddress string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	args := m.Called(poolAddress)
 | 
			
		||||
func (m MockAccountService) GetPoolSwappableVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	args := m.Called(poolAddress, publicKey)
 | 
			
		||||
	return args.Get(0).([]dataserviceapi.TokenHoldings), args.Error(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -115,8 +92,3 @@ func (m MockAccountService) GetSwapFromTokenMaxLimit(ctx context.Context, poolAd
 | 
			
		||||
	args := m.Called(poolAddress, fromTokenAddress, toTokenAddress, publicKey)
 | 
			
		||||
	return args.Get(0).(*models.MaxLimitResult), args.Error(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m MockAccountService) CheckTokenInPool(ctx context.Context, poolAddress, tokenAddress string) (*models.TokenInPoolResult, error) {
 | 
			
		||||
	args := m.Called(poolAddress, tokenAddress)
 | 
			
		||||
	return args.Get(0).(*models.TokenInPoolResult), args.Error(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -35,10 +35,10 @@ func (tas *TestAccountService) TrackAccountStatus(ctx context.Context, publicKey
 | 
			
		||||
func (tas *TestAccountService) FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	return []dataserviceapi.TokenHoldings{
 | 
			
		||||
		dataserviceapi.TokenHoldings{
 | 
			
		||||
			TokenAddress:  "0x6CC75A06ac72eB4Db2eE22F781F5D100d8ec03ee",
 | 
			
		||||
			TokenSymbol:   "SRF",
 | 
			
		||||
			TokenDecimals: "6",
 | 
			
		||||
			Balance:       "2745987",
 | 
			
		||||
			ContractAddress: "0x6CC75A06ac72eB4Db2eE22F781F5D100d8ec03ee",
 | 
			
		||||
			TokenSymbol:     "SRF",
 | 
			
		||||
			TokenDecimals:   "6",
 | 
			
		||||
			Balance:         "2745987",
 | 
			
		||||
		},
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
@ -61,43 +61,23 @@ func (m TestAccountService) PoolDeposit(ctx context.Context, amount, from, poolA
 | 
			
		||||
	return &models.PoolDepositResult{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *TestAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
 | 
			
		||||
func (m TestAccountService) CheckAliasAddress(ctx context.Context, alias string) (*models.AliasAddress, error) {
 | 
			
		||||
	return &models.AliasAddress{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *TestAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
 | 
			
		||||
func (m TestAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
 | 
			
		||||
	return &models.RequestAliasResult{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *TestAccountService) UpdateAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
 | 
			
		||||
	return &models.RequestAliasResult{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *TestAccountService) SendUpsellSMS(ctx context.Context, inviterPhone, inviteePhone string) (*models.SendSMSResponse, error) {
 | 
			
		||||
	return &models.SendSMSResponse{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *TestAccountService) SendAddressSMS(ctx context.Context, publicKey, originPhone string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *TestAccountService) SendPINResetSMS(ctx context.Context, admin, phone string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m TestAccountService) FetchTopPools(ctx context.Context) ([]dataserviceapi.PoolDetails, error) {
 | 
			
		||||
	return []dataserviceapi.PoolDetails{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m TestAccountService) RetrievePoolDetails(ctx context.Context, sym string) (*dataserviceapi.PoolDetails, error) {
 | 
			
		||||
	return &dataserviceapi.PoolDetails{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m TestAccountService) GetPoolSwappableFromVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	return []dataserviceapi.TokenHoldings{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m TestAccountService) GetPoolSwappableVouchers(ctx context.Context, poolAddress string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
func (m TestAccountService) GetPoolSwappableVouchers(ctx context.Context, poolAddress, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	return []dataserviceapi.TokenHoldings{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -112,7 +92,3 @@ func (m TestAccountService) PoolSwap(ctx context.Context, amount, from, fromToke
 | 
			
		||||
func (m TestAccountService) GetSwapFromTokenMaxLimit(ctx context.Context, poolAddress, fromTokenAddress, toTokenAddress, publicKey string) (*models.MaxLimitResult, error) {
 | 
			
		||||
	return &models.MaxLimitResult{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m TestAccountService) CheckTokenInPool(ctx context.Context, poolAddress, tokenAddress string) (*models.TokenInPoolResult, error) {
 | 
			
		||||
	return &models.TokenInPoolResult{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user