plp_go_sdk

package module
v0.0.0-...-4d9bc2d Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 16 Imported by: 0

README

PLP version

0.0.1

demo

package main

import ( "time"

"github.com/Polyflow-Protocol/PLP_go_sdk"
"github.com/Polyflow-Protocol/PLP_go_sdk/config"

)

func main() { var conf *config.Config = &config.Config{ Debug: &config.DebugConfig{ Enable: false, Verbose: false, }, DB: &config.DBConfig{ Host: "127.0.0.1", Port: 3306, User: "root", Password: "123456", DbName: "plp", TimeZone: "Local", }, Redis: &config.RedisConfig{ RedisIsCluster: false, RedisClient: &config.RedisClientOpt{}, RedisClusterClient: &config.RedisClusterClientOpt{}, }, Admin: &config.AdminConfig{ OwnerPriKey: "xxx", }, Contracts: make([]*config.ContractConf, 0), Expiry: 30 * time.Minute, } svr := plp_go_sdk.NewServer(conf) svr.Start() }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignWallet

func AssignWallet(
	chainId uint64, holderAddress, pfTokenReceiverAddress, invoiceNumber, notifyUrl string,
	payableAmount, validityTerm uint64) (address, uuid string, expireTime uint64, err error)

*

  • Assign the given wallet or create a new one to the specified holder.
  • For a given wallet, must check if the wallet is assignable. Any extra fund tokens in a wallet should be swept
  • to this pool before being assigned, so that the actual fund token balance of the wallet would be exactly the
  • same as its recorded balance.
  • @param wallet_ Wallet to be assigned. A new wallet will be created if the given `wallet_` is the zero address.
  • @param holder_ The new holder that the wallet will be assigned to.
  • @param pfTokenReceiver_ The address to receive pfTokens when the payment is completed.
  • @param payableAmount_ The amount to be paid.
  • @param validityTerm_ The validity term of the wallet. `DEFAULT_VALIDITY_TERM` would be applied if the given
  • `validityTerm_` is 0.
  • @return The address of the assigned wallet and its expire time.

func Claim

func Claim(chainId uint64) (totalClaimAmount uint64, err error)

*

  • Claim all fund tokens that have exceeded the waiting period.

func GetARP

func GetARP(chainId, date uint64) (apr string, err error)

func GetLastARP

func GetLastARP(chainId uint64) (apr string, err error)

func GetRequestRedemptionWallets

func GetRequestRedemptionWallets(chainId uint64, redeemAmount *big.Int) (redemptionWalletMap map[string]string, err error)

*

  • Request redemption by specifying the wallets to be collected and the amount of tokens to be collected.
  • @param redeemAmount_ The amount of pfTokens for redeeming.
  • @returns redemptionWalletMap key: wallets_ The addresses of wallets to collect funds from.
  • @returns redemptionWalletMap val: collectAmounts_ The token amount to collect from each wallet.

func GetTVL

func GetTVL(chainId uint64) (amount uint64, err error)

*

  • Returns the TVL in the pool, deducting the amount of fund tokens for redeeming.

func GetUserClaimableAmount

func GetUserClaimableAmount(chainId uint64, address string) (userClaimableAmount uint64, err error)

*

  • Query all redemption records of the given user, and calculate the currently claimable amount.

func GetWithdrawList

func GetWithdrawList(chainId uint64, address, orderby string, offset, limit int) ([]*dao.PftokenWithdrawDetail, error)

func HandleWalletDeposit

func HandleWalletDeposit(chainId uint64, address string) error

*

  • Verify if the wallet payemnt has been completed, if so, update the status of the wallet and the pool,
  • and mint pfTokens to target receiver.
  • @param wallet_ The address of wallet to be deposited.

func IsWalletAssignable

func IsWalletAssignable(chainId uint64, address string) (ok bool, err error)

*

  • Returns if the wallet is able to be assigned to a new user.
  • An assignable wallet should exist in the wallet pool and have not unexpired,
  • and the fund token balance should be equal to the recorded balance, which means
  • that the last payment has been completed and the wallet is ready to be reassigned.

func IsWalletValid

func IsWalletValid(chainId uint64, address string) (ok bool, err error)

*

  • Returns if the wallet exists in the pool, regardless of whether it is expired.

func PaymentNotifyReset

func PaymentNotifyReset(chainId uint64, uuid string) (err error)

func Rebase

func Rebase(chainId uint64) error

*

  • Rebase by updating the value of base reserve by calculating the latest TVL in the plp address pool.
  • After rebasing, the totalSupply of plp token will be equal to the amount of fund tokens in the plp
  • address pool, thus keeping the exchange rate at 1:1.

func RefundFromWallet

func RefundFromWallet(chainId uint64, address string) (refundAmount string, err error)

* * Execute refund from the given wallet. This function can only be called by the owner, so that to * prevent it from being abused. e.g., there may be a delay between the user payment (before expire * time) and the `handleWalletDeeposit` process (after expire time), if the refund process is * triggered before `handleWalletDeposit`, then the user payment would be deemed failed.

func RequestRedemption

func RequestRedemption(chainId uint64, redeemAmount uint64, redemptionWalletMap map[string]uint64) (claimableTime uint64, err error)

func StartScanTasks

func StartScanTasks()

func SwapMoney

func SwapMoney(
	chainId, amount uint64, address, invoiceNumber, notifyUrl string) (
	uuid string, err error)

func SwapNotifyReset

func SwapNotifyReset(chainId uint64, uuid string) (err error)

func WalletCount

func WalletCount(chainId uint64) (total uint64, err error)

*

  • Returns the count of wallets in the pool.

func WithdrawRefundTokens

func WithdrawRefundTokens(chainId uint64, address, amount string) error

*

  • Withdraw the fund tokens that are refunded from wallets.

Types

type PlpServer

type PlpServer struct {
	Server     *asynq.Server
	TaskClient *tasks.TaskClient
	Conf       *config.Config
}

func NewServer

func NewServer(conf *config.Config) *PlpServer

func (*PlpServer) Start

func (svr *PlpServer) Start()

type SwapRateResponse

type SwapRateResponse struct {
	Amount          *big.Int `json:"amount"`
	ActualAmount    *big.Int `json:"actual_amount"`
	LiquidityTarget *big.Int `json:"liquidity_target"`
	Reserve         *big.Int `json:"reserve"`
	Fee             *big.Int `json:"fee"`
	Decimals        uint8    `json:"decimals"`
	FeeRate         *big.Int `json:"fee_rate"`
	MinFee          *big.Int `json:"min_fee"`
	MaxFee          *big.Int `json:"max_fee"`
	FeeDecimals     uint8    `json:"fee_decimals"`
}

func SwapRate

func SwapRate(chainId, amount uint64) (res *SwapRateResponse, err error)

Jump to

Keyboard shortcuts

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