gosuilending

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

go-sui-lending

Documentation

Index

Constants

View Source
const (
	CallTypeSupply    = 0
	CallTypeWithdraw  = 1
	CallTypeBorrow    = 2
	CallTypeRepay     = 3
	CallTypeLiquidite = 4
	CallTypeBinding   = 5
	CallTypeUnbinding = 6
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BindingArgs

type BindingArgs struct {
	WormholeMessageCoins  []sui_types.ObjectID // vector<Coin<SUI>>
	WormholeMessageAmount string
	DolaChainId           uint16
	BindAddress           string
}

type BorrowArgs

type BorrowArgs struct {
	Pool     sui_types.ObjectID
	Receiver string
	DstChain string
	Amount   string
}

type CallOptions

type CallOptions struct {
	Gas       *sui_types.ObjectID
	GasBudget uint64
}

type CollateralItem

type CollateralItem struct {
	CollateralAmount *big.Int
	CollateralValue  *big.Int
	DolaPoolId       uint16
	BorrowApy        int
	SupplyApy        int
}

type Contract

type Contract struct {
	// contains filtered or unexported fields
}

func NewContract

func NewContract(client *client.Client, config ContractConfig) (*Contract, error)

func (*Contract) BorrowLocal added in v0.0.2

func (c *Contract) BorrowLocal(ctx context.Context, signer sui_types.SuiAddress, typeArgs []string, borrowArgs BorrowArgs, callOptions CallOptions) (*types.TransactionBytes, error)

func (*Contract) GetAllOraclePrice

func (c *Contract) GetAllOraclePrice(ctx context.Context, signer sui_types.SuiAddress, callOptions CallOptions) (prices []DolaTokenPrice, err error)

func (*Contract) GetAllPoolLiquidity

func (c *Contract) GetAllPoolLiquidity(ctx context.Context, signer sui_types.SuiAddress, dolaPoolId uint16, callOptions CallOptions) (poolInfos []PoolInfo, err error)

GetAllPoolLiquidity return all chain liquidity of a dola pool

func (*Contract) GetAllReserveInfo

func (c *Contract) GetAllReserveInfo(ctx context.Context, signer sui_types.SuiAddress, callOptions CallOptions) (reserveInfos []ReserveInfo, err error)

func (*Contract) GetAppTokenLiquidity

func (c *Contract) GetAppTokenLiquidity(ctx context.Context, signer sui_types.SuiAddress, appId uint16, dolaPoolId uint16, callOptions CallOptions) (liquidity *big.Int, err error)

func (*Contract) GetDolaTokenLiquidity

func (c *Contract) GetDolaTokenLiquidity(ctx context.Context, signer sui_types.SuiAddress, dolaPoolId uint16, callOptions CallOptions) (liquidity *big.Int, err error)

func (*Contract) GetDolaUserAddresses

func (c *Contract) GetDolaUserAddresses(ctx context.Context, signer sui_types.SuiAddress, dolaUserId string, callOptions CallOptions) (dolaUserAddresses []DolaUserAddress, err error)

func (*Contract) GetDolaUserId

func (c *Contract) GetDolaUserId(ctx context.Context, signer sui_types.SuiAddress, dolaChainId uint16, user string, callOptions CallOptions) (userId string, err error)

GetDolaUserId return dola_user_id for (dola_chain_id, address) pair if not exist, an error return

func (*Contract) GetOraclePrice

func (c *Contract) GetOraclePrice(ctx context.Context, signer sui_types.SuiAddress, dolaPoolId uint16, callOptions CallOptions) (dolaTokenPrice DolaTokenPrice, err error)

func (*Contract) GetPoolLiquidity

func (c *Contract) GetPoolLiquidity(ctx context.Context, signer sui_types.SuiAddress, dolaChainId uint16, poolAddress string, callOptions CallOptions) (liquidity *big.Int, err error)

GetPoolLiquidity return a pool liquidity on a chain

func (*Contract) GetReserveInfo

func (c *Contract) GetReserveInfo(ctx context.Context, signer sui_types.SuiAddress, dolaPoolId uint16, callOptions CallOptions) (reserveInfo *ReserveInfo, err error)

func (*Contract) GetUserAllowedBorrow

func (c *Contract) GetUserAllowedBorrow(ctx context.Context, signer sui_types.SuiAddress, dolaUserId string, borrowPoolId uint16, callOptions CallOptions) (amount *big.Int, err error)

func (*Contract) GetUserCollateral

func (c *Contract) GetUserCollateral(ctx context.Context, signer sui_types.SuiAddress, dolaUserId string, dolaPoolId uint16, callOptions CallOptions) (collateral CollateralItem, err error)

func (*Contract) GetUserHealthFactor

func (c *Contract) GetUserHealthFactor(ctx context.Context, signer sui_types.SuiAddress, dolaUserId string, callOptions CallOptions) (healthFactor *big.Int, err error)

func (*Contract) GetUserLendingInfo

func (c *Contract) GetUserLendingInfo(ctx context.Context, signer sui_types.SuiAddress, dolaUserId string, callOptions CallOptions) (userLendingInfo *UserLendingInfo, err error)

func (*Contract) GetUserTokenDebt

func (c *Contract) GetUserTokenDebt(ctx context.Context, signer sui_types.SuiAddress, dolaUserId string, dolaPoolId uint16, callOptions CallOptions) (debtAmount *big.Int, debtValue *big.Int, err error)

func (*Contract) Repay

func (c *Contract) Repay(ctx context.Context, signer sui_types.SuiAddress, typeArgs []string, repayArgs RepayArgs, callOptions CallOptions) (*types.TransactionBytes, error)

func (*Contract) SendBinding

func (c *Contract) SendBinding(ctx context.Context, signer sui_types.SuiAddress, typeArgs []string, bindingArgs BindingArgs, callOptions CallOptions) (*types.TransactionBytes, error)

func (*Contract) SendingUnbinding

func (c *Contract) SendingUnbinding(ctx context.Context, signer sui_types.SuiAddress, typeArgs []string, unbindingArgs UnbindingArgs, callOptions CallOptions) (*types.TransactionBytes, error)

func (*Contract) Supply

func (c *Contract) Supply(ctx context.Context, signer sui_types.SuiAddress, typeArgs []string, supplyArgs SupplyArgs, callOptions CallOptions) (*types.TransactionBytes, error)

func (*Contract) WithdrawLocal added in v0.0.2

func (c *Contract) WithdrawLocal(ctx context.Context, signer sui_types.SuiAddress, typeArgs []string, withdrawArgs WithdrawArgs, callOptions CallOptions) (*types.TransactionBytes, error)

func (*Contract) WithdrawRemote added in v0.0.2

func (c *Contract) WithdrawRemote(ctx context.Context, signer sui_types.SuiAddress, typeArgs []string, withdrawArgs WithdrawArgs, callOptions CallOptions) (*types.TransactionBytes, error)

type ContractConfig

type ContractConfig struct {
	LendingPortalPackageId     string
	ExternalInterfacePackageId string
	BridgePoolPackageId        string
	PoolManagerInfo            string
	PoolState                  string
	PriceOracle                string
	Storage                    string
	WormholeState              string
	UserManagerInfo            string
	CoreState                  string
	LendingPortal              string
	LendingCore                string
	Clock                      string
	PoolApproval               string
}

type DebtItem

type DebtItem struct {
	DebtAmount *big.Int
	DebtValue  *big.Int
	DolaPoolId uint16
	BorrowApy  int
	SupplyApy  int
}

type DolaTokenPrice

type DolaTokenPrice struct {
	Decimal    int // the decimal of price,
	DolaPoolId uint16
	Price      *big.Int
}

type DolaUserAddress

type DolaUserAddress struct {
	DolaChainId uint16
	DolaAddress string // hex string. 0x123
}

type EventHeader added in v0.0.2

type EventHeader struct {
	Timestamp uint64
	TxDigest  string
	Id        types.EventId
}

type Faucet

type Faucet interface {
	Claim(ctx context.Context, signer sui_types.SuiAddress, typeArgs []string, callOptions CallOptions) (*types.TransactionBytes, error)
}

func NewFaucet

func NewFaucet(client *client.Client, packageId, faucetId string) (Faucet, error)

type LendingCoreEvent added in v0.0.2

type LendingCoreEvent struct {
	MoveEventHeader MoveEventHeader
	Nonce           uint64
	SenderUserId    uint64
	SourceChainId   uint16
	DstChainId      uint16
	DolaPoolId      uint16
	Receiver        []byte
	Amount          uint64
	LiquidateUserId uint64
	CallType        int
}

bridge send event, from other chain transaction

func ParseLendingCoreEvent added in v0.0.2

func ParseLendingCoreEvent(event types.SuiEvent) (result *LendingCoreEvent, err error)

type LendingCoreExecuteEvent added in v0.0.3

type LendingCoreExecuteEvent struct {
	MoveEventHeader MoveEventHeader
	UserId          uint64
	Amount          *big.Int
	PoolId          uint16
	ViolatorId      uint64
	CallType        int
}

core event

func ParseLendingCoreExecuteEvent added in v0.0.3

func ParseLendingCoreExecuteEvent(event types.SuiEvent) (result *LendingCoreExecuteEvent, err error)

type LendingPortalEvent added in v0.0.2

type LendingPortalEvent struct {
	MoveEventHeader MoveEventHeader
	Nonce           uint64
	Sender          string
	DolaPoolAddress []byte
	SourceChainId   uint16
	DstChainId      uint16
	Receiver        []byte
	Amount          uint64
	CallType        int
}

Sui chain call remote borrow/withdraw

func ParseLendingPortalEvent added in v0.0.2

func ParseLendingPortalEvent(event types.SuiEvent) (result *LendingPortalEvent, err error)

type LocalLendingEvent added in v0.0.2

type LocalLendingEvent struct {
	MoveEventHeader MoveEventHeader
	Nonce           uint64
	Sender          string
	DolaPoolAddress []byte
	Amount          uint64
	CallType        int
}

Sui local chain lending event

func ParseLocalLendingEvent added in v0.0.2

func ParseLocalLendingEvent(event types.SuiEvent) (result *LocalLendingEvent, err error)

type MoveEventHeader added in v0.0.2

type MoveEventHeader struct {
	EventHeader
	PackageId         string
	TransactionModule string
	Sender            string
	Type              string
	Bcs               string
}

type PoolInfo

type PoolInfo struct {
	PoolLiquidity      *big.Int
	DolaChainId        uint16
	DolaAddress        string   // hex string. 0x123
	PoolEquilibriumFee *big.Int // u256
	PoolWeight         *big.Int // u256
}

type RepayArgs

type RepayArgs struct {
	Pool        sui_types.ObjectID
	RepayCoins  []*sui_types.ObjectID // vector<Coin<CoinType>>
	RepayAmount string
}

type ReserveInfo

type ReserveInfo struct {
	BorrowApy             int // 200 -> 200/10000=2.0%
	BorrowCoefficient     *big.Int
	CollateralCoefficient *big.Int
	Debt                  *big.Int // 100000000 -> 100000000/1e8 = 1
	Reserve               *big.Int // 100000000 -> 100000000/1e8 = 1
	SupplyApy             int      // 100 -> 100/10000=1.0%
	UtilizationRate       int      // 100 -> 100/10000=1.0%
	DolaPoolId            uint16
	Pools                 []PoolInfo
}

type SupplyArgs

type SupplyArgs struct {
	Pool          sui_types.ObjectID
	DepositCoins  []*sui_types.ObjectID // vector<Coin<CoinType>>
	DepositAmount string
}

type UnbindingArgs

type UnbindingArgs struct {
	WormholeMessageCoins  []sui_types.ObjectID // vector<Coin<SUI>>
	WormholeMessageAmount string
	DolaChainId           uint16
	UnbindAddress         string
}

type UserLendingInfo

type UserLendingInfo struct {
	TotalCollateralValue *big.Int
	TotalDebtValue       *big.Int
	HealthFactor         *big.Int
	NetApy               int // profit_state decide positive or negtive
	TotalBorrowApy       int
	TotalSupplyApy       int

	CollateralInfos []CollateralItem
	DebtInfos       []DebtItem
}

type WithdrawArgs

type WithdrawArgs struct {
	Pool           sui_types.ObjectID
	Receiver       string
	DstChain       string
	Amount         string
	RelayFeeCoins  []*sui_types.ObjectID
	RelayFeeAmount string
}

Jump to

Keyboard shortcuts

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