Skip to content

Commit b797977

Browse files
committed
v1.6.7
1 parent a33a744 commit b797977

File tree

8 files changed

+108
-26
lines changed

8 files changed

+108
-26
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.6.7 - 2023-11-17
4+
### Updated
5+
- Imporve stardard withdrawal
6+
37
## 1.6.6 - 2023-10-25
48
### Updated
59
- RoundCeil for sell price, roundFloor for buy price

cmd/test/account_client_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,16 @@ func TestGetOpenOrders(t *testing.T) {
282282
t.Logf("%v", lib.String(r))
283283
}
284284
}
285+
286+
func TestGetEstimatedWithdrawalGasFees(t *testing.T) {
287+
client := new(spot.Client)
288+
client.SetAppConfig(appConfig)
289+
response, err := client.GetEstimatedWithdrawalGasFee(appConfig.AccountAddress, 0)
290+
if err != nil {
291+
t.Errorf("%v", err)
292+
} else if response.Success() {
293+
t.Logf("%v", lib.String(response.Data))
294+
} else {
295+
t.Logf("%v", lib.String(response))
296+
}
297+
}

degate/binance/common.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ type GasFeeResponse struct {
4040
}
4141

4242
type OffChainFee struct {
43-
UpdateAccountGasFees []*GasFee `json:"update_account_gas_fees"`
44-
WithdrawalGasFees []*GasFee `json:"withdrawal_gas_fees"`
45-
TransferGasFees []*GasFee `json:"transfer_gas_fees"`
46-
TransferNoIDGasFees []*GasFee `json:"transfer_no_id_gas_fees"`
47-
OrderGasFees []*GasFee `json:"order_gas_fees"`
48-
AddPairGasFees []*GasFee `json:"add_pair_gas_fees"`
49-
MiningGasFees []*GasFee `json:"mining_gas_fees"`
50-
OnChainCancelOrderGasFees []*GasFee `json:"on_chain_cancel_order_gas_fees"`
51-
OrderGasMultiple uint32 `json:"order_gas_multiple"`
43+
UpdateAccountGasFees []*GasFee `json:"update_account_gas_fees"`
44+
WithdrawalGasFees []*GasFee `json:"withdrawal_gas_fees"`
45+
EstimatedWithdrawalGasFees []*GasFee `json:"estimated_withdrawal_gas_fees"`
46+
TransferGasFees []*GasFee `json:"transfer_gas_fees"`
47+
TransferNoIDGasFees []*GasFee `json:"transfer_no_id_gas_fees"`
48+
OrderGasFees []*GasFee `json:"order_gas_fees"`
49+
AddPairGasFees []*GasFee `json:"add_pair_gas_fees"`
50+
MiningGasFees []*GasFee `json:"mining_gas_fees"`
51+
OnChainCancelOrderGasFees []*GasFee `json:"on_chain_cancel_order_gas_fees"`
52+
OrderGasMultiple uint32 `json:"order_gas_multiple"`
5253
}
5354

5455
type GasFee struct {

degate/lib/convert.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,8 @@ func ConvertGasFees(fees *model.GasFees, tokens []*model.TokenInfo) (offChainFee
876876

877877
offChainFee.WithdrawalGasFees, err = ConvertGasFee(fees.WithdrawalGasFees, tokens)
878878

879+
offChainFee.EstimatedWithdrawalGasFees, err = ConvertGasFee(fees.EstimatedWithdrawalGasFees, tokens)
880+
879881
offChainFee.TransferGasFees, err = ConvertGasFee(fees.TransferGasFees, tokens)
880882

881883
offChainFee.TransferNoIDGasFees, err = ConvertGasFee(fees.TransferNoIDGasFees, tokens)

degate/model/param.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,8 @@ type Token struct {
135135
type DGPairPriceParam struct {
136136
Pairs string `json:"pairs"`
137137
}
138+
139+
type WithdrawalGasParam struct {
140+
To string `json:"to" form:"to" ` // account address
141+
TokenId uint64 `json:"token_id" form:"token_id"` // token id
142+
}

degate/model/user.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,21 @@ type OffChainFee struct {
118118
}
119119

120120
type GasFees struct {
121-
UpdateAccountGasFees *GasFee `json:"update_account_gas_fees"`
122-
WithdrawalGasFees *GasFee `json:"withdrawal_gas_fees"`
123-
TransferGasFees *GasFee `json:"transfer_gas_fees"`
124-
TransferNoIDGasFees *GasFee `json:"transfer_no_id_gas_fees"`
125-
OrderGasFees *GasFee `json:"order_gas_fees"`
126-
AddPairGasFees *GasFee `json:"add_pair_gas_fees"`
127-
MiningGasFees *GasFee `json:"mining_gas_fees"`
128-
OnChainCancelOrderGasFees *GasFee `json:"on_chain_cancel_order_gas_fees"`
129-
DepositFeeConfirmGasFees *GasFee `json:"deposit_fee_confirm_gas_fees"`
130-
EthPrice string `json:"eth_price"`
131-
GasPrice string `json:"gas_price"`
132-
PriorityFee string `json:"priority_fee"`
133-
EnclaveAddress string `json:"enclave_address"`
134-
CreateTime int64 `json:"create_time"`
121+
UpdateAccountGasFees *GasFee `json:"update_account_gas_fees"`
122+
WithdrawalGasFees *GasFee `json:"withdrawal_gas_fees"`
123+
EstimatedWithdrawalGasFees *GasFee `json:"estimated_withdrawal_gas_fees"`
124+
TransferGasFees *GasFee `json:"transfer_gas_fees"`
125+
TransferNoIDGasFees *GasFee `json:"transfer_no_id_gas_fees"`
126+
OrderGasFees *GasFee `json:"order_gas_fees"`
127+
AddPairGasFees *GasFee `json:"add_pair_gas_fees"`
128+
MiningGasFees *GasFee `json:"mining_gas_fees"`
129+
OnChainCancelOrderGasFees *GasFee `json:"on_chain_cancel_order_gas_fees"`
130+
DepositFeeConfirmGasFees *GasFee `json:"deposit_fee_confirm_gas_fees"`
131+
EthPrice string `json:"eth_price"`
132+
GasPrice string `json:"gas_price"`
133+
PriorityFee string `json:"priority_fee"`
134+
EnclaveAddress string `json:"enclave_address"`
135+
CreateTime int64 `json:"create_time"`
135136
}
136137

137138
func (g *GasFees) GetTokenIds() (ids map[uint64]uint64) {
@@ -146,6 +147,11 @@ func (g *GasFees) GetTokenIds() (ids map[uint64]uint64) {
146147
ids[token.TokenID] = token.TokenID
147148
}
148149
}
150+
if g.EstimatedWithdrawalGasFees != nil {
151+
for _, token := range g.EstimatedWithdrawalGasFees.Tokens {
152+
ids[token.TokenID] = token.TokenID
153+
}
154+
}
149155
if g.TransferGasFees != nil {
150156
for _, token := range g.TransferGasFees.Tokens {
151157
ids[token.TokenID] = token.TokenID

degate/spot/account_client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,8 @@ func (c *Client) Withdraw(param *model.WithdrawParam) (response *binance.Withdra
595595
}
596596
volume = quantity.String()
597597

598-
gasResponse, err := c.GetGasFee()
598+
//获取 gas fee
599+
gasResponse, err := c.GetEstimatedWithdrawalGasFee(param.Address, tokenData.TokenID)
599600
if err != nil {
600601
return
601602
}
@@ -604,7 +605,7 @@ func (c *Client) Withdraw(param *model.WithdrawParam) (response *binance.Withdra
604605
return
605606
}
606607

607-
gasFees = gasResponse.Data.WithdrawalGasFees
608+
gasFees = gasResponse.Data.EstimatedWithdrawalGasFees
608609

609610
if len(gasFees) == 0 {
610611
err = fmt.Errorf("not find gas fee token")

degate/spot/exchange_client.go

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package spot
33
import (
44
"errors"
55
"fmt"
6+
"strconv"
7+
68
"github.com/degatedev/degate-sdk-golang/conf"
79
"github.com/degatedev/degate-sdk-golang/degate/request"
8-
"strconv"
910

1011
"github.com/degatedev/degate-sdk-golang/degate/binance"
1112
"github.com/degatedev/degate-sdk-golang/degate/lib"
@@ -66,6 +67,55 @@ func (c *Client) GetGasFee() (response *binance.GasFeeResponse, err error) {
6667
return
6768
}
6869

70+
func (c *Client) GetEstimatedWithdrawalGasFee(toAddr string, tokenId uint64) (response *binance.GasFeeResponse, err error) {
71+
header, err := c.GetHeaderSign()
72+
if err != nil {
73+
return
74+
}
75+
76+
r := &model.WithdrawalGasParam{
77+
To: toAddr,
78+
TokenId: tokenId,
79+
}
80+
81+
res := &model.GasFeeResponse{}
82+
err = c.Get("user/getEstimatedWithdrawalGas", header, r, res)
83+
if err != nil {
84+
return
85+
}
86+
response = &binance.GasFeeResponse{}
87+
if err = model.Copy(response, &res.Response); err != nil {
88+
return
89+
}
90+
if res.Success() && res.Data != nil {
91+
var tokensInfo []*model.TokenInfo
92+
ids := res.Data.GetTokenIds()
93+
if len(ids) > 0 {
94+
var (
95+
idString string
96+
tokenRes *model.TokensResponse
97+
)
98+
for id := range ids {
99+
idString += strconv.Itoa(int(id)) + ","
100+
}
101+
idString = idString[0 : len(idString)-1]
102+
tokenRes, err = c.TokenList(&model.TokenListParam{
103+
Ids: idString,
104+
})
105+
if err != nil {
106+
return
107+
}
108+
if !tokenRes.Success() || len(tokenRes.Data) == 0 {
109+
err = errors.New("not find tokens")
110+
return
111+
}
112+
tokensInfo = tokenRes.Data
113+
}
114+
response.Data, _ = lib.ConvertGasFees(res.Data, tokensInfo)
115+
}
116+
return
117+
}
118+
69119
func (c *Client) GetTradeFee(param *model.TradeFeeParam) (response *binance.TradeFeeResponse, err error) {
70120
res := &model.TradeFeeResponse{}
71121
token := conf.Conf.GetTokenInfo(param.Symbol)

0 commit comments

Comments
 (0)