interswap

package
v0.0.0-...-c0e0e34 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2023 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubmitFailed    int = 0
	FirstPending        = 1
	FirstRefunding      = 2
	FirstRefunded       = 3
	MidRefunding        = 4
	MidRefunded         = 5
	SecondPending       = 6
	SecondRefunding     = 7
	SecondRefunded      = 8
	SecondSuccess       = 9
)
View Source
const DefaultDecimal = 9
View Source
const INTERSWAP_TX_TOPIC = "interswaptx_topic"
View Source
const IncNetworkStr = "inc"
View Source
const InterSwapStr = "interswap"
View Source
const InterswapPappPdexTask = "interswaptx_pathtype2" // Path 2: pApp => pDEX
View Source
const InterswapPdexPappTxTask = "interswaptx_pathtype1" // Path 1: pDEX => pApp

task by swap path

View Source
const InterswapPendingStr = "Pending"
View Source
const InterswapRefundedStr = "Refunded"
View Source
const InterswapRefundingStr = "Refunding"
View Source
const InterswapSubmitFailedStr = "Failed"
View Source
const InterswapSuccessStr = "Success"
View Source
const MaxNumRecheck = 5
View Source
const MaxNumRetry = 1
View Source
const MinBalance = 400000000
View Source
const PAppStr = "papp"
View Source
const PAppToPdex = 2
View Source
const PdexToPApp = 1

path type

Variables

View Source
var BEEndpoint = os.Getenv("BE_ENDPOINT")
View Source
var InterswapIncKeySets map[string]*wallet.KeyWallet
View Source
var IsUpdate = false
View Source
var SkipTxs = []string{
	"82a30987e144aed3f3a3c56c0f1209477fe1c0444d8c38643989674ed24bf339",
	"b8d289152ca4e8819a2cc81cc5cff59ca999a71d80b34c2160df320936cbe669",
	"1cd9e638e1a10182348dae56ca974356c5ee2d876b7ba0fedcb44594a08c8711",
}
View Source
var SlackAlert = os.Getenv("INTERSWAP_SLACK_ALERT")
View Source
var SlackInfo = os.Getenv("INTERSWAP_SLACK_INFO")
View Source
var SupportedMidTokens = []string{}

Functions

func CallGetPdexSwapTxStatus

func CallGetPdexSwapTxStatus(txhash string, config beCommon.Config) (bool, *beCommon.TradeDataRespond, error)

func CallGetTxsByCoinPubKeys2

func CallGetTxsByCoinPubKeys2(coinPubKeys []string, config beCommon.Config, incClient *incclient.IncClient) (map[string]map[string]metadata.Transaction, error)

func CallSubmitPappSwapTx

func CallSubmitPappSwapTx(txRaw, txHash, feeRefundOTA string, config beCommon.Config, endpoint string) (map[string]interface{}, error)

CallSubmitPappSwapTx calls request to submit tx papp

func CheckIncTxIsConfirmed

func CheckIncTxIsConfirmed(txID string, numRecheck uint) (isConfirm bool, isMaxRecheck bool, shouldRefund bool, numRecheckRes uint, err error)

func CheckStatusAndHandlePappTx

func CheckStatusAndHandlePappTx(txData *beCommon.InterSwapTxData, config beCommon.Config) error

func CheckStatusAndHandlePappTxSecond

func CheckStatusAndHandlePappTxSecond(txData *beCommon.InterSwapTxData, config beCommon.Config) error

func CheckStatusAndHandlePdexTx

func CheckStatusAndHandlePdexTx(txData *beCommon.InterSwapTxData, config beCommon.Config) error

func CheckStatusAndHandlePdexTxSecond

func CheckStatusAndHandlePdexTxSecond(txData *beCommon.InterSwapTxData, config beCommon.Config) error

CheckStatusAndHandlePdexTxSecond

func ConvertAmountToWithoutDec

func ConvertAmountToWithoutDec(amt uint64, pDecimal uint64) (float64, error)

func ConvertUint64ToWithoutDecStr

func ConvertUint64ToWithoutDecStr(amt uint64, tokenID string, config common.Config) (string, error)

func ConvertUint64ToWithoutDecStr2

func ConvertUint64ToWithoutDecStr2(amt uint64, pDecimal uint64) (string, error)

func EstimateSwap

func EstimateSwap(params *EstimateSwapParam, config common.Config) (map[string][]InterSwapEstRes, error)

InterSwap estimate swap

func GetBestRoute

func GetBestRoute(paths map[string][]QuoteData) map[string]*QuoteData

GetBestRoute return the best one for each network (pdex & papps), and the best one for all pApps

func GetChildTokenUnified

func GetChildTokenUnified(tokenID string, networkID int, config beCommon.Config) (string, error)

GetChildTokenUnified returns child token of unified token if token is not unified, return itself

func Has0xPrefix

func Has0xPrefix(str string) bool

func InitIncClient

func InitIncClient(network string, config common.Config) error

func InitSupportedMidTokens

func InitSupportedMidTokens(network string) error

func IsExist

func IsExist(strArr []string, str string) bool

func IsMidTokens

func IsMidTokens(tokenID string) bool

func IsOnlySwappablePDexToken

func IsOnlySwappablePDexToken(tokenInfo common.TokenInfo) bool

func IsUniqueSlices

func IsUniqueSlices(s []string) bool

func MarshalCoin

func MarshalCoin(utxos []coin.PlainCoin) []string

func ParseUserAgent

func ParseUserAgent(userAgent string) string

func ProcessInterswapTxRequest

func ProcessInterswapTxRequest(ctx context.Context, m *pubsub.Message)

func Remove0xPrefix

func Remove0xPrefix(str string) string

Remove0xPrefix removes 0x prefix (if there) from string

func SendSlackAlert

func SendSlackAlert(msg string)

func SendSlackInfo

func SendSlackInfo(msg string)

func SendSlackSwapInfo

func SendSlackSwapInfo(
	interswapID string, userAgent string, status string,
	fromAmt uint64, fromToken string, toAmt uint64, toToken string,
	receiveAmt uint64, receiveToken string,
	config beCommon.Config,
) error

func StartWorker

func StartWorker(cfg wcommon.Config, serviceID uuid.UUID) error

func UnmarshalCoin

func UnmarshalCoin(utxoStrs []string) ([]coin.PlainCoin, error)

Types

type AddOnSwapInfo

type AddOnSwapInfo struct {
	AppName      string
	CallContract string
	FromToken    string
	ToToken      string

	MinExpectedAmt uint64
}

type EstimateSwapParam

type EstimateSwapParam struct {
	Network   string
	Amount    string
	Slippage  string
	FromToken string // IncTokenID
	ToToken   string // IncTokenID
	ShardID   string
}

type EstimateSwapResponse

type EstimateSwapResponse struct {
	Result EstimateSwapResult
	Error  interface{}
}

type EstimateSwapResult

type EstimateSwapResult struct {
	Networks      map[string][]QuoteData
	NetworksError map[string]interface{}
}

func CallEstimateSwap

func CallEstimateSwap(params *EstimateSwapParam, config beCommon.Config, endpoint string) (*EstimateSwapResult, error)

CallEstimateSwap call request to estimate swap for both pdex and papp

type InterSwapEstRes

type InterSwapEstRes struct {
	QuoteData
	PathType  int
	FromToken string
	ToToken   string
	MidToken  string
	MidOTA    string
	TotalFee  PappNetworkFee
	Details   []*QuoteData
}

type InterSwapPath

type InterSwapPath struct {
	Paths     []*QuoteData
	FromToken string
	ToToken   string
	MidToken  string
	TotalFee  PappNetworkFee
}

type InterswapSubmitTxTask

type InterswapSubmitTxTask struct {
	TxID                string `json:"txid" bson:"txid"`
	TxRawBytes          []byte `json:"txraw" bson:"txraw"`
	FromToken           string `json:"fromtoken" bson:"fromtoken"`
	ToToken             string `json:"totoken" bson:"totoken"`
	MidToken            string `json:"midtoken" bson:"midtoken"`
	PathType            int    `json:"pathtype" bson:"pathtype"`
	FinalMinExpectedAmt uint64 `json:"final_minacceptedamount" bson:"final_minacceptedamount"`

	OTARefundFee string `json:"ota_refundfee" bson:"ota_refundfee"`
	OTARefund    string `json:"ota_refund" bson:"ota_refund"`
	OTAFromToken string `json:"ota_fromtoken" bson:"ota_fromtoken"`
	OTAToToken   string `json:"ota_totoken" bson:"ota_totoken"`

	AddOnTxID    string `json:"addon_txid" bson:"addon_txid"`
	PAppName     string `json:"papp_name" bson:"papp_name"`
	PAppNetwork  string `json:"papp_network" bson:"papp_network"`
	PAppContract string `json:"papp_contract" bson:"papp_contract"`

	Status    int    `json:"status" bson:"status"`
	StatusStr string `json:"statusstr" bson:"statusstr"`
	UserAgent string `json:"useragent" bson:"useragent"`
	Error     string `json:"error" bson:"error"`
}

type PappNetworkFee

type PappNetworkFee struct {
	TokenID          string  `json:"tokenid"`
	Amount           uint64  `json:"amount"`
	AmountInBuyToken string  `json:"amountInBuyToken"`
	PrivacyFee       uint64  `json:"privacyFee"`
	FeeInUSD         float64 `json:"feeInUSD"`
}

type PappStatus

type PappStatus struct {
	BurnStatus    string
	SwapStatus    string
	IsRedeposit   bool
	IsRedeposited bool
	BuyAmount     string
	Reward        string
}

type QuoteData

type QuoteData struct {
	AppName              string
	PAppNetwork          string
	CallContract         string
	AmountIn             string
	AmountInRaw          string
	AmountOut            string
	AmountOutRaw         string
	AmountOutPreSlippage string
	RedepositReward      string
	Rate                 string
	Fee                  []PappNetworkFee
	FeeAddress           string
	FeeAddressShardID    int
	Paths                interface{}
	PathsContract        interface{}
	PoolPairs            []string
	Calldata             string
	ImpactAmount         string
	RouteDebug           interface{}
}

type ReceivedTransactionV2

type ReceivedTransactionV2 struct {
	TxDetail struct {
		BlockHash   string `json:"BlockHash"`
		BlockHeight uint64 `json:"BlockHeight"`
		TxSize      uint64 `json:"TxSize"`
		Index       uint64 `json:"Index"`
		ShardID     byte   `json:"ShardID"`
		Hash        string `json:"Hash"`
		Version     int8   `json:"Version"`
		Type        string `json:"Type"` // Transaction type
		LockTime    string `json:"LockTime"`
		Fee         uint64 `json:"Fee"` // Fee applies: always consant
		Image       string `json:"Image"`

		IsPrivacy bool          `json:"IsPrivacy"`
		Proof     privacy.Proof `json:"Proof"`
		// ProofDetail      jsonresult.ProofDetail `json:"ProofDetail"`
		InputCoinPubKey  string   `json:"InputCoinPubKey"`
		OutputCoinPubKey []string `json:"OutputCoinPubKey"`
		OutputCoinSND    []string `json:"OutputCoinSND"`

		TokenInputCoinPubKey  string   `json:"TokenInputCoinPubKey"`
		TokenOutputCoinPubKey []string `json:"TokenOutputCoinPubKey"`
		TokenOutputCoinSND    []string `json:"TokenOutputCoinSND"`

		SigPubKey string `json:"SigPubKey,omitempty"` // 64 bytes
		Sig       string `json:"Sig,omitempty"`       // 64 bytes

		Metatype                 int    `json:"Metatype"`
		Metadata                 string `json:"Metadata"`
		CustomTokenData          string `json:"CustomTokenData"`
		PrivacyCustomTokenID     string `json:"PrivacyCustomTokenID"`
		PrivacyCustomTokenName   string `json:"PrivacyCustomTokenName"`
		PrivacyCustomTokenSymbol string `json:"PrivacyCustomTokenSymbol"`
		PrivacyCustomTokenData   string `json:"PrivacyCustomTokenData"`
		// PrivacyCustomTokenProofDetail jsonresult.ProofDetail `json:"PrivacyCustomTokenProofDetail"`
		PrivacyCustomTokenIsPrivacy bool   `json:"PrivacyCustomTokenIsPrivacy"`
		PrivacyCustomTokenFee       uint64 `json:"PrivacyCustomTokenFee"`

		IsInMempool bool `json:"IsInMempool"`
		IsInBlock   bool `json:"IsInBlock"`

		Info string `json:"Info"`
	}
	FromShardID byte
}

func CallGetTxsByCoinPubKeys

func CallGetTxsByCoinPubKeys(coinPubKeys []string, config beCommon.Config) ([]ReceivedTransactionV2, error)

call through coin service

type ResponseInfo

type ResponseInfo struct {
	Coin      coin.PlainCoin
	CoinIndex *big.Int
	TxID      string
}

type SubmitpAppSwapTxRequest

type SubmitpAppSwapTxRequest struct {
	TxRaw        string
	TxHash       string
	FeeRefundOTA string
}

type SubmitpAppSwapTxResponse

type SubmitpAppSwapTxResponse struct {
	Result map[string]interface{}
}

type TransactionDetail

type TransactionDetail struct {
	BlockHash   string `json:"BlockHash"`
	BlockHeight uint64 `json:"BlockHeight"`
	TxSize      uint64 `json:"TxSize"`
	Index       uint64 `json:"Index"`
	ShardID     byte   `json:"ShardID"`
	Hash        string `json:"Hash"`
	Version     int8   `json:"Version"`
	Type        string `json:"Type"` // Transaction type
	LockTime    string `json:"LockTime"`
	RawLockTime int64  `json:"RawLockTime,omitempty"`
	Fee         uint64 `json:"Fee"` // Fee applies: always consant
	Image       string `json:"Image"`

	IsPrivacy bool `json:"IsPrivacy"`
	// Proof           privacy.Proof `json:"Proof"`
	// ProofDetail     interface{}   `json:"ProofDetail"`
	InputCoinPubKey string `json:"InputCoinPubKey"`
	SigPubKey       string `json:"SigPubKey,omitempty"` // 64 bytes
	RawSigPubKey    []byte `json:"RawSigPubKey,omitempty"`
	Sig             string `json:"Sig,omitempty"` // 64 bytes

	Metadata                      string      `json:"Metadata"`
	CustomTokenData               string      `json:"CustomTokenData"`
	PrivacyCustomTokenID          string      `json:"PrivacyCustomTokenID"`
	PrivacyCustomTokenName        string      `json:"PrivacyCustomTokenName"`
	PrivacyCustomTokenSymbol      string      `json:"PrivacyCustomTokenSymbol"`
	PrivacyCustomTokenData        string      `json:"PrivacyCustomTokenData"`
	PrivacyCustomTokenProofDetail interface{} `json:"PrivacyCustomTokenProofDetail"`
	PrivacyCustomTokenIsPrivacy   bool        `json:"PrivacyCustomTokenIsPrivacy"`
	PrivacyCustomTokenFee         uint64      `json:"PrivacyCustomTokenFee"`

	IsInMempool bool `json:"IsInMempool"`
	IsInBlock   bool `json:"IsInBlock"`

	Info string `json:"Info"`
}

func CallGetTxDetails

func CallGetTxDetails(txhash string, config beCommon.Config) (*TransactionDetail, error)

type TxStatusRespond

type TxStatusRespond struct {
	TxHash string
	Status string
	Error  string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL