|
1 | 1 | import argparse
|
2 | 2 | import asyncio
|
| 3 | +import base64 |
3 | 4 | import hashlib
|
4 | 5 | import logging
|
5 | 6 | import struct
|
|
8 | 9 | import httpx
|
9 | 10 | from solana.rpc.async_api import AsyncClient
|
10 | 11 | from solana.transaction import Transaction
|
| 12 | +from solders.hash import Hash |
11 | 13 | from solders.instruction import AccountMeta, Instruction
|
12 |
| -from solders.message import Message |
| 14 | +from solders.message import MessageV0 |
| 15 | +from solders.null_signer import NullSigner |
13 | 16 | from solders.pubkey import Pubkey
|
14 | 17 | from solders.system_program import ID as system_pid
|
15 | 18 | from solders.sysvar import INSTRUCTIONS as sysvar_ixs_pid
|
| 19 | +from solders.transaction import VersionedTransaction |
16 | 20 |
|
17 | 21 | from per_sdk.svm.helpers import configure_logger, read_kp_from_json
|
18 | 22 |
|
@@ -73,6 +77,12 @@ def parse_args() -> argparse.Namespace:
|
73 | 77 | default=False,
|
74 | 78 | help="Submit the transaction directly on-chain instead of submitting to the server",
|
75 | 79 | )
|
| 80 | + parser.add_argument( |
| 81 | + "--use-legacy-transaction-bid", |
| 82 | + action="store_true", |
| 83 | + default=False, |
| 84 | + help="Use the legacy transaction message format instead of the versioned message format for the bid. Only applies if transaction is submitted as a bid (i.e. --submit-on-chain is not set)", |
| 85 | + ) |
76 | 86 | return parser.parse_args()
|
77 | 87 |
|
78 | 88 |
|
@@ -138,27 +148,37 @@ async def main():
|
138 | 148 | ],
|
139 | 149 | )
|
140 | 150 |
|
141 |
| - tx = Transaction() |
142 |
| - tx.add(ix_submit_bid) |
143 |
| - tx.add(ix_dummy) |
144 |
| - |
145 | 151 | if args.submit_on_chain:
|
146 | 152 | client = AsyncClient(args.rpc_url, "confirmed")
|
| 153 | + tx = Transaction(fee_payer=kp_searcher.pubkey()) |
| 154 | + tx.add(ix_submit_bid) |
| 155 | + tx.add(ix_dummy) |
147 | 156 | tx_sig = (
|
148 | 157 | await client.send_transaction(tx, kp_searcher, kp_relayer_signer)
|
149 | 158 | ).value
|
150 | 159 | conf = await client.confirm_transaction(tx_sig)
|
151 | 160 | assert conf.value[0].status is None, "Transaction failed"
|
152 | 161 | logger.info(f"Submitted transaction with signature {tx_sig}")
|
153 | 162 | else:
|
154 |
| - tx.sign_partial(kp_searcher) |
155 |
| - message = bytes(Message([ix_submit_bid, ix_dummy], pk_searcher)) |
156 |
| - # TODO: impute one signature into the message |
| 163 | + if args.use_legacy_transaction_bid: |
| 164 | + tx = Transaction(fee_payer=kp_searcher.pubkey()) |
| 165 | + tx.add(ix_submit_bid) |
| 166 | + tx.add(ix_dummy) |
| 167 | + tx.sign_partial(kp_searcher) |
| 168 | + serialized = base64.b64encode( |
| 169 | + tx.serialize(verify_signatures=False) |
| 170 | + ).decode() |
| 171 | + else: |
| 172 | + messagev0 = MessageV0.try_compile( |
| 173 | + kp_searcher.pubkey(), [ix_submit_bid, ix_dummy], [], Hash.default() |
| 174 | + ) |
| 175 | + signers = [kp_searcher, NullSigner(kp_relayer_signer.pubkey())] |
| 176 | + partially_signed = VersionedTransaction(messagev0, signers) |
| 177 | + serialized = base64.b64encode(bytes(partially_signed)).decode() |
| 178 | + |
157 | 179 | bid_body = {
|
158 |
| - "permission_key": str(permission), |
159 | 180 | "chain_id": "solana",
|
160 |
| - "amount": args.bid, |
161 |
| - "transaction": message.hex(), |
| 181 | + "transaction": serialized, |
162 | 182 | }
|
163 | 183 | client = httpx.AsyncClient()
|
164 | 184 | resp = await client.post(
|
|
0 commit comments