Hi All,
Having difficulty swapping bLuna to Luna via a Python script. I haven’t had issues doing the following:
- Swapping Luna to UST
- Swapping Luna for bLuna
- Swapping bLuna for Luna on the test net
Any help would be much appreciated
This is my code:
from terra_sdk.client.lcd import LCDClient
from terra_sdk.core.market import MsgSwap
from terra_sdk.core.bank import MsgSend
from terra_sdk.client.lcd.api.tx import CreateTxOptions
from terra_sdk.core.wasm import MsgExecuteContract
# Import other stuff
import requests
import json
terra = LCDClient(
chain_id="columbus-5",
url="https://lcd.terra.dev")
terra
# Create wallet
from terra_sdk.key.mnemonic import MnemonicKey
mk = MnemonicKey("my seed phrase")
# Initialize the wallet
wallet = terra.wallet(mk)
# Astroport pair address
bLuna_Luna_Pair_Addresses = "terra1j66jatn3k50hjtg2xemnjm8s7y8dws9xqa5y8w"
bLuna_contract = "terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp"
def Swap_bLuna_for_Luna(bluna_to_be_swapped1):
send_Swap_bLuna_for_Luna = (
MsgExecuteContract(
sender=mk.acc_address,
contract=bLuna_contract,
execute_msg={
"send": {
"msg": "eyJzd2FwIjp7Im1heF9zcHJlYWQiOiIwLjAwNSJ9fQ==", #'{"swap":{"max_spread":"0.005"}}' converted from json to Base64. Refer to https://docs.terraswap.io/docs/howto/swap/
"amount": str(bluna_to_be_swapped1),
"contract": "terra1j66jatn3k50hjtg2xemnjm8s7y8dws9xqa5y8w"
}
},
),
)
# Send tx
tx_Swap_bLuna_for_Luna = wallet.create_and_sign_tx(
CreateTxOptions(
send_Swap_bLuna_for_Luna
)
)
result_Swap_bLuna_for_Luna = terra.tx.broadcast(tx_Swap_bLuna_for_Luna)
print(result_Swap_bLuna_for_Luna.txhash)
Swap_bLuna_for_Luna(100000)
This is the error message:
“Status 400 - failed to execute message; message index: 0: dispatch: Operation exceeds max spread limit: execute wasm contract failed: invalid request”