Documentation ¶
Index ¶
- Constants
- Variables
- func FactToCondition(factRegistryAddress string, fact string) *big.Int
- func GenerateKRfc6979(msgHash, priKey *big.Int, seed int) *big.Int
- func GetTransferErc20Fact(recipient string, tokenDecimals int, humanAmount, tokenAddress, salt string) (string, error)
- func IntToHex32(x *big.Int) string
- func NonceByClientId(clientId string) *big.Int
- func OrderSign(starkPrivateKey string, param OrderSignParam) (string, error)
- func PedersenHash(str ...string) string
- func SerializeSignature(r, s *big.Int) string
- func ToJsonString(input interface{}) string
- func TransferSign(starkPrivateKey string, param TransferSignParam) (string, error)
- func WithdrawSign(starkPrivateKey string, param WithdrawSignParam) (string, error)
- type OrderSignParam
- type OrderSigner
- type PedersenCfg
- type Signable
- type Signer
- func (s *Signer) SetNetworkId(networkId int) *Signer
- func (s *Signer) SetSigner(signer Signable) *Signer
- func (s *Signer) Sign() (string, error)
- func (s *Signer) SignOrder(param OrderSignParam) (string, error)
- func (s *Signer) SignTransfer(param TransferSignParam) (string, error)
- func (s *Signer) SignWithdraw(param WithdrawSignParam) (string, error)
- type TransferSignParam
- type TransferSigner
- type WithdrawSignParam
- type WithdrawSigner
Constants ¶
View Source
const ASSET_ID_GOERLI = "0x03bda2b4764039f2df44a00a9cf1d1569a83f95406a983ce4beb95791c376008"
View Source
const ASSET_ID_MAINNET = "0x02893294412a4c8f915f75892b395ebbf6859ec246ec365c3b1f56f47c3a0a5d"
View Source
const ASSET_ID_ROPSTEN = "0x02c04d8b650f44092278a7cb1e1028c82025dff622db96c934b611b84cc8de5a"
View Source
const ASSET_ID_SEPOLIA = "0x01e70c509c4c6bfafe8b73d2fc1819444b2c0b435d4b82c0f24addff9565ce25"
View Source
const COLLATERAL_ASSET = "USDC"
View Source
const COLLATERAL_TOKEN_DECIMALS = 6
View Source
const CONDITIONAL_TRANSFER_FEE_ASSET_ID = 0
View Source
const CONDITIONAL_TRANSFER_MAX_AMOUNT_FEE = 0
View Source
const CONDITIONAL_TRANSFER_PADDING_BITS = 81
View Source
const CONDITIONAL_TRANSFER_PREFIX = 5
View Source
const NETWORK_ID_GOERLI = 5
View Source
const NETWORK_ID_MAINNET = 1
View Source
const NETWORK_ID_ROPSTEN = 3
View Source
const NETWORK_ID_SEPOLIA = 11155111
View Source
const NONCE_UPPER_BOUND_EXCLUSIVE = 1 << 32 // 1 << ORDER_FIELD_BIT_LENGTHS['nonce']
View Source
const ONE_HOUR_IN_SECONDS = 60 * 60
View Source
const ORDER_PADDING_BITS = 17
View Source
const ORDER_PREFIX = 3
View Source
const ORDER_SIGNATURE_EXPIRATION_BUFFER_HOURS = 24 * 7 // Seven days.
View Source
const WITHDRAWAL_PADDING_BITS = 49
View Source
const WITHDRAWAL_PREFIX = 6
Variables ¶
View Source
var ASSET_RESOLUTION = map[string]int64{
"USDC": 1e6,
"BTC": 1e10,
"ETH": 1e9,
"LINK": 1e7,
"AAVE": 1e8,
"UNI": 1e7,
"SUSHI": 1e7,
"SOL": 1e7,
"YFI": 1e10,
"1INCH": 1e7,
"AVAX": 1e7,
"SNX": 1e7,
"CRV": 1e6,
"UMA": 1e7,
"DOT": 1e7,
"DOGE": 1e5,
"MATIC": 1e6,
"MKR": 1e9,
"FIL": 1e7,
"ADA": 1e6,
"ATOM": 1e7,
"COMP": 1e8,
"BCH": 1e8,
"LTC": 1e8,
"EOS": 1e6,
"ALGO": 1e6,
"ZRX": 1e6,
"XMR": 1e8,
"ZEC": 1e8,
"ENJ": 1e6,
"ETC": 1e7,
"XLM": 1e5,
"TRX": 1e4,
"XTZ": 1e6,
"ICP": 1e7,
"RUNE": 1e6,
"LUNA": 1e6,
"NEAR": 1e6,
"CELO": 1e6,
}
View Source
var BIT_MASK_250 = big.NewInt(0).Sub(big.NewInt(0).Exp(big.NewInt(2), big.NewInt(250), nil), one)
BIT_MASK_250 (2 ** 250) - 1
View Source
var COLLATERAL_ASSET_ID_BY_NETWORK_ID = map[int]*big.Int{ NETWORK_ID_MAINNET: mainNet, NETWORK_ID_ROPSTEN: ropstenNet, NETWORK_ID_GOERLI: goerliNet, NETWORK_ID_SEPOLIA: sepoliaNet, }
View Source
var CONDITIONAL_TRANSFER_FIELD_BIT_LENGTHS = map[string]uint{
"asset_id": 250,
"receiver_public_key": 251,
"position_id": 64,
"condition": 251,
"quantums_amount": 64,
"nonce": 32,
"expiration_epoch_hours": 32,
}
View Source
var EC_ORDER = new(big.Int)
View Source
var FACT_REGISTRY_CONTRACT = map[int]string{ NETWORK_ID_MAINNET: "0xBE9a129909EbCb954bC065536D2bfAfBd170d27A", NETWORK_ID_ROPSTEN: "0x8Fb814935f7E63DEB304B500180e19dF5167B50e", NETWORK_ID_GOERLI: "0xc5061C08cF892C79DDB106B777138982433C8865", NETWORK_ID_SEPOLIA: "0xCD828e691cA23b66291ae905491Bb89aEe3Abd82", }
View Source
var FIELD_PRIME = new(big.Int)
View Source
var N_ELEMENT_BITS_ECDSA = big.NewInt(251)
N_ELEMENT_BITS_ECDSA math.floor(math.log(FIELD_PRIME, 2))
View Source
var ORDER_FIELD_BIT_LENGTHS = map[string]uint{
"asset_id_synthetic": 128,
"asset_id_collateral": 250,
"asset_id_fee": 250,
"quantums_amount": 64,
"nonce": 32,
"position_id": 64,
"expiration_epoch_hours": 32,
}
View Source
var SYNTHETIC_ID_MAP = map[string]string{
"BTC": "344400637343183300222065759427231744",
"ETH": "359977924069045087395084506562035712",
"LINK": "396101380212426712967694464499843072",
"AAVE": "338824487460109173243580632516263936",
"UNI": "442933058573725082054137099516379136",
"SUSHI": "432691242383575582125453041830199296",
"SOL": "432568984950746621260512834741075968",
"YFI": "463539986724008297878357474744991744",
"1INCH": "255909362588701076462300859102920704",
"AVAX": "339248760150583523010467496495939584",
"SNX": "432549653279093140762140010017193984",
"CRV": "349553874723416551039058041492209664",
"UMA": "442912142338821316269012403913490432",
"DOT": "354685165898024320947256138154377216",
"DOGE": "354684143347712898450594870927032320",
"MATIC": "401131892570687533667041932340101120",
"MKR": "401334549532515986032888887373725696",
"FIL": "364947431332171952067072698953498624",
"ADA": "338883663480482972844972322892808192",
"ATOM": "339209301121316311335550155636080640",
"COMP": "349492325262502431542334300769746944",
"BCH": "344056232528969600292671285127806976",
"LTC": "396323605936767383653495383972118528",
"EOS": "359877383527187708491834411764940800",
"ALGO": "339046408638152281133665097078538240",
"ZRX": "468976860926042615023934644152172544",
"XMR": "458490379794397467467957612323012608",
"ZEC": "468711525812200195396563123811909632",
"ENJ": "359856388064121428442372122618101760",
"ETC": "359977527925814664434167280492871680",
"XLM": "458469701240354467017001809827856384",
"TRX": "437823079772415797613522407827439616",
"XTZ": "458632990484505291636396733084205056",
"ICP": "380402944362804581987470878609244160",
"RUNE": "427498548421964717489411527496695808",
"LUNA": "396344766032815712432848274622251008",
"NEAR": "406403816491359422489603563510038528",
"CELO": "349289421628808946019446426697728000",
}
View Source
var TOKEN_CONTRACTS = map[string]map[int]string{ COLLATERAL_ASSET: { NETWORK_ID_MAINNET: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", NETWORK_ID_ROPSTEN: "0x8707A5bf4C2842d46B31A405Ba41b858C0F876c4", NETWORK_ID_GOERLI: "0xF7a2fa2c2025fFe64427dd40Dc190d47ecC8B36e", NETWORK_ID_SEPOLIA: "0x7fC9C132268E0E414991449c003DbdB3E73E2059", }, }
View Source
var WITHDRAWAL_FIELD_BIT_LENGTHS = map[string]uint{
"asset_id": 250,
"position_id": 64,
"nonce": 32,
"quantums_amount": 64,
"expiration_epoch_hours": 32,
}
Functions ¶
func FactToCondition ¶
FactToCondition Generate the condition, signed as part of a conditional transfer.
func GetTransferErc20Fact ¶
func GetTransferErc20Fact(recipient string, tokenDecimals int, humanAmount, tokenAddress, salt string) (string, error)
GetTransferErc20Fact get erc20 fact tokenDecimals is COLLATERAL_TOKEN_DECIMALS
func IntToHex32 ¶
IntToHex32 Normalize to a 32-byte hex string without 0x prefix.
func NonceByClientId ¶
NonceByClientId generate nonce by clientId
func PedersenHash ¶
func SerializeSignature ¶
SerializeSignature Convert a Sign from an r, s pair to a 32-byte hex string.
func ToJsonString ¶
func ToJsonString(input interface{}) string
func TransferSign ¶
func TransferSign(starkPrivateKey string, param TransferSignParam) (string, error)
func WithdrawSign ¶
func WithdrawSign(starkPrivateKey string, param WithdrawSignParam) (string, error)
Types ¶
type OrderSignParam ¶
type OrderSignParam struct { NetworkId int `json:"network_id"` // 1 MAINNET 3 ROPSTEN PositionId int64 `json:"position_id"` Market string `json:"market"` Side string `json:"side"` HumanSize string `json:"human_size"` HumanPrice string `json:"human_price"` LimitFee string `json:"limit_fee"` ClientId string `json:"clientId"` Expiration string `json:"expiration"` // 2006-01-02T15:04:05.000Z }
type OrderSigner ¶
type OrderSigner struct {
// contains filtered or unexported fields
}
type PedersenCfg ¶
type Signer ¶
type Signer struct { NetworkId int // contains filtered or unexported fields }
func (*Signer) SetNetworkId ¶
func (*Signer) SignTransfer ¶
func (s *Signer) SignTransfer(param TransferSignParam) (string, error)
func (*Signer) SignWithdraw ¶
func (s *Signer) SignWithdraw(param WithdrawSignParam) (string, error)
type TransferSignParam ¶
type TransferSignParam struct { NetworkId int `json:"network_id"` // 1 MAINNET 3 ROPSTEN SenderPositionId int64 `json:"sender_position_id"` ReceiverPositionId int64 `json:"receiver_position_id"` ReceiverPublicKey string `json:"receiver_public_key"` ReceiverAddress string `json:"receiver_address"` CreditAmount string `json:"credit_amount"` DebitAmount string `json:"debit_amount"` Expiration string `json:"expiration"` ClientId string `json:"client_id"` }
type TransferSigner ¶
type TransferSigner struct {
// contains filtered or unexported fields
}
type WithdrawSignParam ¶
type WithdrawSigner ¶
type WithdrawSigner struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.