Skip to content

Commit da49b27

Browse files
Merge pull request #138 from InjectiveLabs/f/add_send_to_injective
feat: add SendToInjective
2 parents bbfa704 + 38b642d commit da49b27

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,24 @@ async def main() -> None:
1515
network = Network.testnet()
1616
peggo_composer = Peggo(network=network.string())
1717

18-
private_key = "f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3"
19-
ethereum_endpoint = "https://kovan.infura.io/v3/c518f454950e48aeab12161c49f26e30"
18+
private_key = "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e"
19+
ethereum_endpoint = "https://eth-goerli.g.alchemy.com/v2/q-7JVv4mTfsNh1y_djKkKn3maRBGILLL"
2020

2121
maxFeePerGas_Gwei = 4
2222
maxPriorityFeePerGas_Gwei = 4
2323

24-
token_contract = "0x36b3d7ace7201e28040eff30e815290d7b37ffad"
24+
token_contract = "0xBe8d71D26525440A03311cc7fa372262c5354A3c"
2525
receiver = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
2626
amount = 1
2727

28+
data = '{"@type": "/injective.exchange.v1beta1.MsgDeposit","sender": "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku","subaccountId": "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000","amount": {"denom": "inj","amount": "1000000000000000000"}}'
29+
2830
import_peggo = pkg_resources.read_text(pyinjective, 'Peggo_ABI.json')
2931
peggo_abi = json.loads(import_peggo)
3032

31-
peggo_composer.SendToCosmos(ethereum_endpoint=ethereum_endpoint, private_key=private_key, token_contract=token_contract,
32-
receiver=receiver, amount=amount, maxFeePerGas=maxFeePerGas_Gwei, maxPriorityFeePerGas=maxPriorityFeePerGas_Gwei, peggo_abi=peggo_abi)
33+
peggo_composer.sendToInjective(ethereum_endpoint=ethereum_endpoint, private_key=private_key, token_contract=token_contract,
34+
receiver=receiver, amount=amount, maxFeePerGas=maxFeePerGas_Gwei, maxPriorityFeePerGas=maxPriorityFeePerGas_Gwei, data=data, peggo_abi=peggo_abi)
3335

3436
if __name__ == "__main__":
3537
logging.basicConfig(level=logging.INFO)
36-
asyncio.get_event_loop().run_until_complete(main())
38+
asyncio.get_event_loop().run_until_complete(main())

pyinjective/Peggo_ABI.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,15 @@
110110
"internalType": "uint256",
111111
"name": "_eventNonce",
112112
"type": "uint256"
113+
},
114+
{
115+
"indexed": false,
116+
"internalType": "string",
117+
"name": "_data",
118+
"type": "string"
113119
}
114120
],
115-
"name": "SendToCosmosEvent",
121+
"name": "SendToInjectiveEvent",
116122
"type": "event"
117123
},
118124
{
@@ -393,9 +399,14 @@
393399
"internalType": "uint256",
394400
"name": "_amount",
395401
"type": "uint256"
402+
},
403+
{
404+
"internalType": "string",
405+
"name": "_data",
406+
"type": "string"
396407
}
397408
],
398-
"name": "sendToCosmos",
409+
"name": "sendToInjective",
399410
"outputs":
400411
[],
401412
"stateMutability": "nonpayable",

pyinjective/sendtocosmos.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
class Peggo:
99
def __init__(self, network: str):
1010
self.network = network
11-
def SendToCosmos(self, ethereum_endpoint: str, private_key: str, token_contract: str, receiver: str, amount: int,
12-
maxFeePerGas: int, maxPriorityFeePerGas: int, peggo_abi: str, decimals=18):
11+
def sendToInjective(self, ethereum_endpoint: str, private_key: str, token_contract: str, receiver: str, amount: int,
12+
maxFeePerGas: int, maxPriorityFeePerGas: int, peggo_abi: str, data: str, decimals=18):
1313
if self.network == 'testnet':
1414
peggy_proxy_address = "0xd2C6753F6B1783EF0a3857275e16e79D91b539a3"
1515
elif self.network == 'mainnet':
1616
peggy_proxy_address = "0xF955C57f9EA9Dc8781965FEaE0b6A2acE2BAD6f3"
17+
elif self.network == 'devnet':
18+
peggy_proxy_address = "0x4F38F75606d046819638f909b66B112aF1095e8d"
1719
else:
18-
logging.info("SendToCosmos is only supported on Mainnet & Testnet")
20+
logging.info("Network is not supported")
1921
web3 = Web3(Web3.HTTPProvider(ethereum_endpoint))
2022
contract = web3.eth.contract(address=peggy_proxy_address, abi=peggo_abi)
2123

@@ -35,10 +37,11 @@ def SendToCosmos(self, ethereum_endpoint: str, private_key: str, token_contract:
3537

3638
amount_to_send = int(amount * pow(10, decimals))
3739

38-
gas = contract.functions.sendToCosmos(
40+
gas = contract.functions.sendToInjective(
3941
token_contract_address,
4042
destination,
4143
amount_to_send,
44+
data
4245
).estimateGas({'from': sender_address_checksum})
4346

4447
transaction_body = {
@@ -48,10 +51,11 @@ def SendToCosmos(self, ethereum_endpoint: str, private_key: str, token_contract:
4851
'maxPriorityFeePerGas': web3.toWei(maxPriorityFeePerGas, 'gwei'),
4952
}
5053

51-
tx = contract.functions.sendToCosmos(
54+
tx = contract.functions.sendToInjective(
5255
token_contract_address,
5356
destination,
5457
amount_to_send,
58+
data
5559
).buildTransaction(transaction_body)
5660

5761
signed_tx = web3.eth.account.signTransaction(tx, private_key=private_key)

0 commit comments

Comments
 (0)