Skip to content

Commit 50190a7

Browse files
authored
feat/chain_upgrade_v1_15 (#175)
* feat: added a documentation page for the new txfees module * feat: updated changelog. Updated documentation about gas heuristics estimator in Python SDK
1 parent 71aaa07 commit 50190a7

25 files changed

+1365
-317
lines changed

source/includes/_account.md

Lines changed: 83 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import dotenv
2020
from grpc import RpcError
2121

2222
from pyinjective.async_client import AsyncClient
23-
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
23+
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
2424
from pyinjective.core.network import Network
2525
from pyinjective.transaction import Transaction
2626
from pyinjective.wallet import PrivateKey
@@ -70,7 +70,10 @@ async def main() -> None:
7070
return
7171

7272
# build tx
73-
gas_price = GAS_PRICE
73+
gas_price = await client.current_chain_gas_price()
74+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
75+
gas_price = int(gas_price * 1.1)
76+
7477
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
7578
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
7679
fee = [
@@ -107,16 +110,12 @@ import (
107110
"time"
108111

109112
"cosmossdk.io/math"
110-
111-
"github.com/InjectiveLabs/sdk-go/client"
112-
113-
"github.com/InjectiveLabs/sdk-go/client/common"
114-
113+
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
115114
sdktypes "github.com/cosmos/cosmos-sdk/types"
116115

117116
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
118117
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
119-
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
118+
"github.com/InjectiveLabs/sdk-go/client/common"
120119
)
121120

122121
func main() {
@@ -153,13 +152,17 @@ func main() {
153152
chainClient, err := chainclient.NewChainClient(
154153
clientCtx,
155154
network,
156-
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
157155
)
158156

159157
if err != nil {
160158
panic(err)
161159
}
162160

161+
gasPrice := chainClient.CurrentChainGasPrice()
162+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
163+
gasPrice = int64(float64(gasPrice) * 1.1)
164+
chainClient.SetGasPrice(gasPrice)
165+
163166
msg := &exchangetypes.MsgDeposit{
164167
Sender: senderAddress.String(),
165168
SubaccountId: "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
@@ -185,6 +188,11 @@ func main() {
185188
}
186189

187190
fmt.Println("gas fee:", gasFee, "INJ")
191+
192+
gasPrice = chainClient.CurrentChainGasPrice()
193+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
194+
gasPrice = int64(float64(gasPrice) * 1.1)
195+
chainClient.SetGasPrice(gasPrice)
188196
}
189197
```
190198
<!-- MARKDOWN-AUTO-DOCS:END -->
@@ -312,7 +320,7 @@ import dotenv
312320
from grpc import RpcError
313321

314322
from pyinjective.async_client import AsyncClient
315-
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
323+
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
316324
from pyinjective.core.network import Network
317325
from pyinjective.transaction import Transaction
318326
from pyinjective.wallet import PrivateKey
@@ -360,7 +368,10 @@ async def main() -> None:
360368
return
361369

362370
# build tx
363-
gas_price = GAS_PRICE
371+
gas_price = await client.current_chain_gas_price()
372+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
373+
gas_price = int(gas_price * 1.1)
374+
364375
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
365376
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
366377
fee = [
@@ -398,7 +409,6 @@ import (
398409

399410
"cosmossdk.io/math"
400411

401-
"github.com/InjectiveLabs/sdk-go/client"
402412
"github.com/InjectiveLabs/sdk-go/client/common"
403413

404414
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
@@ -443,13 +453,17 @@ func main() {
443453
chainClient, err := chainclient.NewChainClient(
444454
clientCtx,
445455
network,
446-
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
447456
)
448457

449458
if err != nil {
450459
panic(err)
451460
}
452461

462+
gasPrice := chainClient.CurrentChainGasPrice()
463+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
464+
gasPrice = int64(float64(gasPrice) * 1.1)
465+
chainClient.SetGasPrice(gasPrice)
466+
453467
msg := &exchangetypes.MsgWithdraw{
454468
Sender: senderAddress.String(),
455469
SubaccountId: "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
@@ -475,6 +489,11 @@ func main() {
475489
}
476490

477491
fmt.Println("gas fee:", gasFee, "INJ")
492+
493+
gasPrice = chainClient.CurrentChainGasPrice()
494+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
495+
gasPrice = int64(float64(gasPrice) * 1.1)
496+
chainClient.SetGasPrice(gasPrice)
478497
}
479498
```
480499
<!-- MARKDOWN-AUTO-DOCS:END -->
@@ -603,7 +622,7 @@ import dotenv
603622
from grpc import RpcError
604623

605624
from pyinjective.async_client import AsyncClient
606-
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
625+
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
607626
from pyinjective.core.network import Network
608627
from pyinjective.transaction import Transaction
609628
from pyinjective.wallet import PrivateKey
@@ -658,7 +677,10 @@ async def main() -> None:
658677
return
659678

660679
# build tx
661-
gas_price = GAS_PRICE
680+
gas_price = await client.current_chain_gas_price()
681+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
682+
gas_price = int(gas_price * 1.1)
683+
662684
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
663685
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
664686
fee = [
@@ -695,14 +717,12 @@ import (
695717
"time"
696718

697719
"cosmossdk.io/math"
698-
699-
"github.com/InjectiveLabs/sdk-go/client"
700-
"github.com/InjectiveLabs/sdk-go/client/common"
720+
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
721+
sdktypes "github.com/cosmos/cosmos-sdk/types"
701722

702723
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
703724
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
704-
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
705-
sdktypes "github.com/cosmos/cosmos-sdk/types"
725+
"github.com/InjectiveLabs/sdk-go/client/common"
706726
)
707727

708728
func main() {
@@ -741,13 +761,17 @@ func main() {
741761
chainClient, err := chainclient.NewChainClient(
742762
clientCtx,
743763
network,
744-
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
745764
)
746765

747766
if err != nil {
748767
panic(err)
749768
}
750769

770+
gasPrice := chainClient.CurrentChainGasPrice()
771+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
772+
gasPrice = int64(float64(gasPrice) * 1.1)
773+
chainClient.SetGasPrice(gasPrice)
774+
751775
msg := &exchangetypes.MsgSubaccountTransfer{
752776
Sender: senderAddress.String(),
753777
SourceSubaccountId: "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
@@ -774,6 +798,11 @@ func main() {
774798
}
775799

776800
fmt.Println("gas fee:", gasFee, "INJ")
801+
802+
gasPrice = chainClient.CurrentChainGasPrice()
803+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
804+
gasPrice = int64(float64(gasPrice) * 1.1)
805+
chainClient.SetGasPrice(gasPrice)
777806
}
778807
```
779808
<!-- MARKDOWN-AUTO-DOCS:END -->
@@ -903,7 +932,7 @@ import dotenv
903932
from grpc import RpcError
904933

905934
from pyinjective.async_client import AsyncClient
906-
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
935+
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
907936
from pyinjective.core.network import Network
908937
from pyinjective.transaction import Transaction
909938
from pyinjective.wallet import PrivateKey
@@ -958,7 +987,10 @@ async def main() -> None:
958987
return
959988

960989
# build tx
961-
gas_price = GAS_PRICE
990+
gas_price = await client.current_chain_gas_price()
991+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
992+
gas_price = int(gas_price * 1.1)
993+
962994
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
963995
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
964996
fee = [
@@ -995,14 +1027,12 @@ import (
9951027
"time"
9961028

9971029
"cosmossdk.io/math"
998-
999-
"github.com/InjectiveLabs/sdk-go/client"
1000-
"github.com/InjectiveLabs/sdk-go/client/common"
1030+
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
1031+
sdktypes "github.com/cosmos/cosmos-sdk/types"
10011032

10021033
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
10031034
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
1004-
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
1005-
sdktypes "github.com/cosmos/cosmos-sdk/types"
1035+
"github.com/InjectiveLabs/sdk-go/client/common"
10061036
)
10071037

10081038
func main() {
@@ -1041,13 +1071,17 @@ func main() {
10411071
chainClient, err := chainclient.NewChainClient(
10421072
clientCtx,
10431073
network,
1044-
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
10451074
)
10461075

10471076
if err != nil {
10481077
panic(err)
10491078
}
10501079

1080+
gasPrice := chainClient.CurrentChainGasPrice()
1081+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
1082+
gasPrice = int64(float64(gasPrice) * 1.1)
1083+
chainClient.SetGasPrice(gasPrice)
1084+
10511085
msg := &exchangetypes.MsgExternalTransfer{
10521086
Sender: senderAddress.String(),
10531087
SourceSubaccountId: "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
@@ -1074,6 +1108,11 @@ func main() {
10741108
}
10751109

10761110
fmt.Println("gas fee:", gasFee, "INJ")
1111+
1112+
gasPrice = chainClient.CurrentChainGasPrice()
1113+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
1114+
gasPrice = int64(float64(gasPrice) * 1.1)
1115+
chainClient.SetGasPrice(gasPrice)
10771116
}
10781117
```
10791118
<!-- MARKDOWN-AUTO-DOCS:END -->
@@ -1203,7 +1242,7 @@ import requests
12031242
from grpc import RpcError
12041243

12051244
from pyinjective.async_client import AsyncClient
1206-
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
1245+
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
12071246
from pyinjective.core.network import Network
12081247
from pyinjective.transaction import Transaction
12091248
from pyinjective.wallet import PrivateKey
@@ -1263,7 +1302,10 @@ async def main() -> None:
12631302
return
12641303

12651304
# build tx
1266-
gas_price = GAS_PRICE
1305+
gas_price = await client.current_chain_gas_price()
1306+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
1307+
gas_price = int(gas_price * 1.1)
1308+
12671309
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
12681310
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
12691311
fee = [
@@ -1300,8 +1342,6 @@ import (
13001342
"time"
13011343

13021344
"cosmossdk.io/math"
1303-
1304-
"github.com/InjectiveLabs/sdk-go/client"
13051345
"github.com/InjectiveLabs/sdk-go/client/common"
13061346

13071347
peggytypes "github.com/InjectiveLabs/sdk-go/chain/peggy/types"
@@ -1346,13 +1386,17 @@ func main() {
13461386
chainClient, err := chainclient.NewChainClient(
13471387
clientCtx,
13481388
network,
1349-
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
13501389
)
13511390

13521391
if err != nil {
13531392
panic(err)
13541393
}
13551394

1395+
gasPrice := chainClient.CurrentChainGasPrice()
1396+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
1397+
gasPrice = int64(float64(gasPrice) * 1.1)
1398+
chainClient.SetGasPrice(gasPrice)
1399+
13561400
ethDest := "0xaf79152ac5df276d9a8e1e2e22822f9713474902"
13571401

13581402
amount := sdktypes.Coin{
@@ -1386,6 +1430,11 @@ func main() {
13861430
}
13871431

13881432
fmt.Println("gas fee:", gasFee, "INJ")
1433+
1434+
gasPrice = chainClient.CurrentChainGasPrice()
1435+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
1436+
gasPrice = int64(float64(gasPrice) * 1.1)
1437+
chainClient.SetGasPrice(gasPrice)
13891438
}
13901439
```
13911440
<!-- MARKDOWN-AUTO-DOCS:END -->

0 commit comments

Comments
 (0)