Compare commits
3 Commits
31eb30de0f
...
aef8efa2bf
Author | SHA1 | Date | |
---|---|---|---|
aef8efa2bf | |||
a1fe416f51 | |||
3473a4413b |
@ -15,7 +15,10 @@ const (
|
|||||||
voucherHoldingsPathPrefix = "/api/v1/holdings"
|
voucherHoldingsPathPrefix = "/api/v1/holdings"
|
||||||
voucherTransfersPathPrefix = "/api/v1/transfers/last10"
|
voucherTransfersPathPrefix = "/api/v1/transfers/last10"
|
||||||
voucherDataPathPrefix = "/api/v1/token"
|
voucherDataPathPrefix = "/api/v1/token"
|
||||||
AliasPrefix = "api/v1/alias"
|
aliasPrefix = "api/v1/alias"
|
||||||
|
poolDepositPrefix = "/api/v2/pool/deposit"
|
||||||
|
poolSwapQoutePrefix = "/api/v2/pool/quote"
|
||||||
|
poolSwapPrefix = "/api/v2/pool/swap"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -34,6 +37,9 @@ var (
|
|||||||
VoucherTransfersURL string
|
VoucherTransfersURL string
|
||||||
VoucherDataURL string
|
VoucherDataURL string
|
||||||
CheckAliasURL string
|
CheckAliasURL string
|
||||||
|
PoolDepositURL string
|
||||||
|
PoolSwapQuoteURL string
|
||||||
|
PoolSwapURL string
|
||||||
)
|
)
|
||||||
|
|
||||||
func setBase() error {
|
func setBase() error {
|
||||||
@ -68,6 +74,10 @@ func LoadConfig() error {
|
|||||||
VoucherHoldingsURL, _ = url.JoinPath(dataURLBase, voucherHoldingsPathPrefix)
|
VoucherHoldingsURL, _ = url.JoinPath(dataURLBase, voucherHoldingsPathPrefix)
|
||||||
VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix)
|
VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix)
|
||||||
VoucherDataURL, _ = url.JoinPath(dataURLBase, voucherDataPathPrefix)
|
VoucherDataURL, _ = url.JoinPath(dataURLBase, voucherDataPathPrefix)
|
||||||
CheckAliasURL, _ = url.JoinPath(dataURLBase, AliasPrefix)
|
CheckAliasURL, _ = url.JoinPath(dataURLBase, aliasPrefix)
|
||||||
|
PoolDepositURL, _ = url.JoinPath(custodialURLBase, poolDepositPrefix)
|
||||||
|
PoolSwapQuoteURL, _ = url.JoinPath(custodialURLBase, poolSwapQoutePrefix)
|
||||||
|
PoolSwapURL, _ = url.JoinPath(custodialURLBase, poolSwapPrefix)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
14
models/pool_swap_response.go
Normal file
14
models/pool_swap_response.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type PoolDepositResult struct {
|
||||||
|
TrackingId string `json:"trackingId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PoolSwapQuoteResult struct {
|
||||||
|
IncludesFeesDeduction bool `json:"includesFeesDeduction"`
|
||||||
|
OutValue string `json:"outValue"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PoolSwapResult struct {
|
||||||
|
TrackingId string `json:"trackingId"`
|
||||||
|
}
|
@ -239,6 +239,86 @@ func resolveAliasAddress(ctx context.Context, alias string) (*models.AliasAddres
|
|||||||
return &r, err
|
return &r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (as *HTTPAccountService) PoolDeposit(ctx context.Context, amount, from, poolAddress, tokenAddress string) (*models.PoolDepositResult, error) {
|
||||||
|
var r models.PoolDepositResult
|
||||||
|
|
||||||
|
//pool deposit payload
|
||||||
|
payload := map[string]string{
|
||||||
|
"amount": amount,
|
||||||
|
"from": from,
|
||||||
|
"poolAddress": poolAddress,
|
||||||
|
"tokenAddress": tokenAddress,
|
||||||
|
}
|
||||||
|
|
||||||
|
payloadBytes, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", config.TokenTransferURL, 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) GetPoolSwapQuote(ctx context.Context, amount, from, fromTokenAddress, poolAddress, toTokenAddress string) (*models.PoolSwapQuoteResult, error) {
|
||||||
|
var r models.PoolSwapQuoteResult
|
||||||
|
|
||||||
|
//pool swap quote payload
|
||||||
|
payload := map[string]string{
|
||||||
|
"amount": amount,
|
||||||
|
"from": from,
|
||||||
|
"fromTokenAddress": fromTokenAddress,
|
||||||
|
"poolAddress": poolAddress,
|
||||||
|
"toTokenAddress": toTokenAddress,
|
||||||
|
}
|
||||||
|
|
||||||
|
payloadBytes, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", config.PoolSwapQuoteURL, 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) PoolSwap(ctx context.Context, amount, from, fromTokenAddress, poolAddress, toTokenAddress string) (*models.PoolSwapResult, error) {
|
||||||
|
var r models.PoolSwapResult
|
||||||
|
|
||||||
|
//swap payload
|
||||||
|
payload := map[string]string{
|
||||||
|
"amount": amount,
|
||||||
|
"from": from,
|
||||||
|
"fromTokenAddress": fromTokenAddress,
|
||||||
|
"poolAddress": poolAddress,
|
||||||
|
"toTokenAddress": toTokenAddress,
|
||||||
|
}
|
||||||
|
|
||||||
|
payloadBytes, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", config.PoolSwapQuoteURL, bytes.NewBuffer(payloadBytes))
|
||||||
|
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
|
// TODO: Use actual custodial api to request available alias
|
||||||
func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
|
func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) {
|
||||||
if as.SS == nil {
|
if as.SS == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user