Skip to content

Commit

Permalink
Merge branch 'main' into feat/bump-and-simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
KahanMajmudar committed Nov 13, 2024
2 parents dfb243a + 8edeef0 commit bead325
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 19 deletions.
8 changes: 6 additions & 2 deletions packages/valory/contracts/agent_mech/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ def get_deliver_to_market_tx(
cls,
ledger_api: LedgerApi,
contract_address: str,
sender_address: str,
request_id: int,
data: str,
mech_staking_instance: str,
Expand All @@ -500,9 +501,12 @@ def get_deliver_to_market_tx(
fn_name="deliverToMarketplace",
args=[
request_id,
data,
bytes.fromhex(data),
Web3.to_checksum_address(mech_staking_instance),
mech_service_id,
],
)
return {"data": bytes.fromhex(tx_data[2:])} # type: ignore
simulation_ok = cls.simulate_tx(
ledger_api, contract_address, sender_address, tx_data
).pop("data")
return {"data": bytes.fromhex(tx_data[2:]), "simulation_ok": simulation_ok} # type: ignore
2 changes: 1 addition & 1 deletion packages/valory/contracts/agent_mech/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeigpq5lxfj2aza6ok3fjuywtdafelkbvoqwaits7regfbgu4oynmku
build/AgentMech.json: bafybeifbx2dovjm7ufoufvxwb5n3tyfcwysecaggpcds4caanqlpfg5dqm
contract.py: bafybeib2wss3fjozfnocvt4yqpwso5ufdaln56q4ug7hwriqfx6u4e7fdu
contract.py: bafybeig5pnbegw4qw3vltgfaay5edf55bkeoewy5dqz6q7dsdclu2doxji
fingerprint_ignore_patterns: []
class_name: AgentMechContract
contract_interface_paths:
Expand Down
27 changes: 17 additions & 10 deletions packages/valory/contracts/mech_marketplace/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"name": "_marketplace",
"type": "address"
},
{
"internalType": "address",
"name": "me",
"type": "address"
},
{
"internalType": "uint256[]",
"name": "_requestIds",
Expand All @@ -57,7 +62,7 @@
"type": "constructor"
}
],
"bytecode": "0x608060405234801561001057600080fd5b5060405161078c38038061078c8339818101604052810190610032919061046d565b60008151905060008167ffffffffffffffff811115610054576100536102f4565b5b6040519080825280602002602001820160405280156100825781602001602082028036833780820191505090505b5090506000805b8381101561018d5760008673ffffffffffffffffffffffffffffffffffffffff1663cb261bec8784815181106100c2576100c16104c9565b5b60200260200101516040518263ffffffff1660e01b81526004016100e69190610507565b608060405180830381865afa158015610103573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101279190610607565b9050806060015163ffffffff1642106101815785828151811061014d5761014c6104c9565b5b6020026020010151848481518110610168576101676104c9565b5b6020026020010181815250508261017e90610663565b92505b81600101915050610089565b5060008167ffffffffffffffff8111156101aa576101a96102f4565b5b6040519080825280602002602001820160405280156101d85781602001602082028036833780820191505090505b50905060005b8281101561022b578381815181106101f9576101f86104c9565b5b6020026020010151828281518110610214576102136104c9565b5b6020026020010181815250508060010190506101de565b5060008160405160200161023f9190610769565b60405160208183030381529060405290506020810180590381f35b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006102998261026e565b9050919050565b60006102ab8261028e565b9050919050565b6102bb816102a0565b81146102c657600080fd5b50565b6000815190506102d8816102b2565b92915050565b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61032c826102e3565b810181811067ffffffffffffffff8211171561034b5761034a6102f4565b5b80604052505050565b600061035e61025a565b905061036a8282610323565b919050565b600067ffffffffffffffff82111561038a576103896102f4565b5b602082029050602081019050919050565b600080fd5b6000819050919050565b6103b3816103a0565b81146103be57600080fd5b50565b6000815190506103d0816103aa565b92915050565b60006103e96103e48461036f565b610354565b9050808382526020820190506020840283018581111561040c5761040b61039b565b5b835b81811015610435578061042188826103c1565b84526020840193505060208101905061040e565b5050509392505050565b600082601f830112610454576104536102de565b5b81516104648482602086016103d6565b91505092915050565b6000806040838503121561048457610483610264565b5b6000610492858286016102c9565b925050602083015167ffffffffffffffff8111156104b3576104b2610269565b5b6104bf8582860161043f565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b610501816103a0565b82525050565b600060208201905061051c60008301846104f8565b92915050565b600080fd5b6105308161028e565b811461053b57600080fd5b50565b60008151905061054d81610527565b92915050565b600063ffffffff82169050919050565b61056c81610553565b811461057757600080fd5b50565b60008151905061058981610563565b92915050565b6000608082840312156105a5576105a4610522565b5b6105af6080610354565b905060006105bf8482850161053e565b60008301525060206105d38482850161053e565b60208301525060406105e78482850161053e565b60408301525060606105fb8482850161057a565b60608301525092915050565b60006080828403121561061d5761061c610264565b5b600061062b8482850161058f565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061066e826103a0565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036106a05761069f610634565b5b600182019050919050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6106e0816103a0565b82525050565b60006106f283836106d7565b60208301905092915050565b6000602082019050919050565b6000610716826106ab565b61072081856106b6565b935061072b836106c7565b8060005b8381101561075c57815161074388826106e6565b975061074e836106fe565b92505060018101905061072f565b5085935050505092915050565b60006020820190508181036000830152610783818461070b565b90509291505056fe",
"bytecode": "0x608060405234801561001057600080fd5b5060405161081738038061081783398181016040528101906100329190610511565b60008151905060008167ffffffffffffffff81111561005457610053610398565b5b6040519080825280602002602001820160405280156100825781602001602082028036833780820191505090505b5090506000805b838110156102055760008773ffffffffffffffffffffffffffffffffffffffff1663cb261bec8784815181106100c2576100c1610580565b5b60200260200101516040518263ffffffff1660e01b81526004016100e691906105be565b608060405180830381865afa158015610103573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101279190610692565b90508673ffffffffffffffffffffffffffffffffffffffff16816000015173ffffffffffffffffffffffffffffffffffffffff1614806101715750806060015163ffffffff164210155b80156101ad5750600073ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff16145b156101f9578582815181106101c5576101c4610580565b5b60200260200101518484815181106101e0576101df610580565b5b602002602001018181525050826101f6906106ee565b92505b81600101915050610089565b5060008167ffffffffffffffff81111561022257610221610398565b5b6040519080825280602002602001820160405280156102505781602001602082028036833780820191505090505b50905060005b828110156102a35783818151811061027157610270610580565b5b602002602001015182828151811061028c5761028b610580565b5b602002602001018181525050806001019050610256565b506000816040516020016102b791906107f4565b60405160208183030381529060405290506020810180590381f35b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610311826102e6565b9050919050565b600061032382610306565b9050919050565b61033381610318565b811461033e57600080fd5b50565b6000815190506103508161032a565b92915050565b61035f81610306565b811461036a57600080fd5b50565b60008151905061037c81610356565b92915050565b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6103d082610387565b810181811067ffffffffffffffff821117156103ef576103ee610398565b5b80604052505050565b60006104026102d2565b905061040e82826103c7565b919050565b600067ffffffffffffffff82111561042e5761042d610398565b5b602082029050602081019050919050565b600080fd5b6000819050919050565b61045781610444565b811461046257600080fd5b50565b6000815190506104748161044e565b92915050565b600061048d61048884610413565b6103f8565b905080838252602082019050602084028301858111156104b0576104af61043f565b5b835b818110156104d957806104c58882610465565b8452602084019350506020810190506104b2565b5050509392505050565b600082601f8301126104f8576104f7610382565b5b815161050884826020860161047a565b91505092915050565b60008060006060848603121561052a576105296102dc565b5b600061053886828701610341565b93505060206105498682870161036d565b925050604084015167ffffffffffffffff81111561056a576105696102e1565b5b610576868287016104e3565b9150509250925092565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6105b881610444565b82525050565b60006020820190506105d360008301846105af565b92915050565b600080fd5b600063ffffffff82169050919050565b6105f7816105de565b811461060257600080fd5b50565b600081519050610614816105ee565b92915050565b6000608082840312156106305761062f6105d9565b5b61063a60806103f8565b9050600061064a8482850161036d565b600083015250602061065e8482850161036d565b60208301525060406106728482850161036d565b604083015250606061068684828501610605565b60608301525092915050565b6000608082840312156106a8576106a76102dc565b5b60006106b68482850161061a565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006106f982610444565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361072b5761072a6106bf565b5b600182019050919050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b61076b81610444565b82525050565b600061077d8383610762565b60208301905092915050565b6000602082019050919050565b60006107a182610736565b6107ab8185610741565b93506107b683610752565b8060005b838110156107e75781516107ce8882610771565b97506107d983610789565b9250506001810190506107ba565b5085935050505092915050565b6000602082019050818103600083015261080e8184610796565b90509291505056fe",
}


Expand Down Expand Up @@ -153,7 +158,7 @@ def get_deliver_data(
fn_name="deliverMarketplace",
args=[
request_id,
data,
bytes.fromhex(data),
delivery_mech_staking_instance,
delivery_mech_service_id,
],
Expand Down Expand Up @@ -186,7 +191,7 @@ def get_request_events(
"tx_hash": entry.transactionHash.hex(),
"block_number": entry.blockNumber,
**entry["args"],
"contract_address": contract_address,
"sender": entry["args"]["requester"],
}
for entry in entries
)
Expand Down Expand Up @@ -239,18 +244,19 @@ def has_priority_passed(
cls,
ledger_api: LedgerApi,
contract_address: str,
my_mech: str,
request_ids: List[int],
) -> Dict[str, Any]:
"""Check the priority of the requests."""
"""Check if requests are ready to be delivered."""
# BatchPriorityData contract is a special contract used specifically for checking if the requests have passed
# the priority timeout. It is not deployed anywhere, nor it needs to be deployed
batch_workable_contract = ledger_api.api.eth.contract(
abi=BATCH_PRIORITY_PASSED_DATA["abi"], bytecode=BATCH_PRIORITY_PASSED_DATA["bytecode"]
)

# Encode the input data (constructor params)
encoded_input_data = ledger_api.api.codec.encode_abi(
["address", "address[]"], [contract_address, request_ids]
encoded_input_data = ledger_api.api.codec.encode(
["address", "address", "uint256[]"], [contract_address, my_mech, request_ids]
)

# Concatenate the bytecode with the encoded input data to create the contract creation code
Expand All @@ -259,12 +265,12 @@ def has_priority_passed(
# Call the function with the contract creation code
# Note that we are not sending any transaction, we are just calling the function
# This is a special contract creation code that will return some result
encoded_strategies = ledger_api.api.eth.call({"data": contract_creation_code})
encoded_req_ids = ledger_api.api.eth.call({"data": contract_creation_code})

# Decode the raw response
# the decoding returns a Tuple with a single element so we need to access the first element of the tuple,
request_ids = ledger_api.api.codec.decode_abi(
["uint256[]"], encoded_strategies
request_ids = ledger_api.api.codec.decode(
["uint256[]"], encoded_req_ids
)[0]
return dict(request_ids=request_ids)

Expand All @@ -274,6 +280,7 @@ def get_undelivered_reqs(
cls,
ledger_api: LedgerApi,
contract_address: str,
my_mech: str,
from_block: BlockIdentifier = "earliest",
to_block: BlockIdentifier = "latest",
max_block_window: int = 1000,
Expand Down Expand Up @@ -306,7 +313,7 @@ def get_undelivered_reqs(
pending_tasks.append(request)

request_ids = [req["requestId"] for req in pending_tasks]
eligible_request_ids = cls.has_priority_passed(ledger_api, contract_address, request_ids).pop("request_ids")
eligible_request_ids = cls.has_priority_passed(ledger_api, contract_address, my_mech, request_ids).pop("request_ids")
pending_tasks = [req for req in pending_tasks if req["requestId"] in eligible_request_ids]
return {"data": pending_tasks}

Expand Down
2 changes: 1 addition & 1 deletion packages/valory/contracts/mech_marketplace/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fingerprint:
BatchPriorityPassedCheck.sol: bafybeie3hfpyss43sggqh5rjzwsqe7o37td4v4k6f3hlweiosnayyseo4i
__init__.py: bafybeigqedpnruwcvjarngql7yfnpqwozvvgzcei2xcrp7mjf4ccspa62y
build/MechMarketplace.json: bafybeiavaelxgltfzquszveskzn732c47tbkyoqd6gwbk3by6ky2n73rcm
contract.py: bafybeibuyclvqogginsusuf5h77iuhwsyustys2thptwcdilu6lk5oo7iq
contract.py: bafybeidwynzoz23yulmxdpe5ae6dx75ozbxm6v3zghzs7pyr6zfhkfkm4q
fingerprint_ignore_patterns: []
class_name: MechMarketplaceContract
contract_interface_paths:
Expand Down
8 changes: 8 additions & 0 deletions packages/valory/services/mech/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type: skill
"tokenId":"2"}}}
agent_funding_amount: ${AGENT_FUNDING_AMOUNT:int:200000000000000000}
minimum_agent_balance: ${MINIMUM_AGENT_BALANCE:int:100000000000000000}
mech_staking_instance_address: ${MECH_STAKING_INSTANCE_ADDRESS:str:0x0000000000000000000000000000000000000000}
service_owner_share: ${SERVICE_SHARE:float:0}
1:
models:
params:
Expand Down Expand Up @@ -105,6 +107,8 @@ type: skill
agent_funding_amount: ${AGENT_FUNDING_AMOUNT:int:200000000000000000}
mech_marketplace_address: ${MECH_MARKETPLACE_ADDRESS:str:0x0000000000000000000000000000000000000000}
minimum_agent_balance: ${MINIMUM_AGENT_BALANCE:int:100000000000000000}
mech_staking_instance_address: ${MECH_STAKING_INSTANCE_ADDRESS:str:0x0000000000000000000000000000000000000000}
service_owner_share: ${SERVICE_SHARE:float:0}
2:
models:
params:
Expand Down Expand Up @@ -143,6 +147,8 @@ type: skill
"tokenId":"2"}}}
agent_funding_amount: ${AGENT_FUNDING_AMOUNT:int:200000000000000000}
minimum_agent_balance: ${MINIMUM_AGENT_BALANCE:int:100000000000000000}
mech_staking_instance_address: ${MECH_STAKING_INSTANCE_ADDRESS:str:0x0000000000000000000000000000000000000000}
service_owner_share: ${SERVICE_SHARE:float:0}
3:
models:
params:
Expand Down Expand Up @@ -181,6 +187,8 @@ type: skill
"tokenId":"2"}}}
agent_funding_amount: ${AGENT_FUNDING_AMOUNT:int:200000000000000000}
minimum_agent_balance: ${MINIMUM_AGENT_BALANCE:int:100000000000000000}
mech_staking_instance_address: ${MECH_STAKING_INSTANCE_ADDRESS:str:0x0000000000000000000000000000000000000000}
service_owner_share: ${SERVICE_SHARE:float:0}
---
public_id: valory/task_execution:0.1.0
type: skill
Expand Down
9 changes: 7 additions & 2 deletions packages/valory/skills/task_submission_abci/behaviours.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ def get_split_profit_txs(
f"Split {profits} profits from mech {mech_address} into {split_funds}"
)
for receiver_address, amount in split_funds.items():
if amount == 0:
continue
tx = yield from self._get_transfer_tx(
mech_address, receiver_address, amount
)
Expand All @@ -386,6 +388,9 @@ def get_split_profit_txs(
return None
txs.append(tx)

if len(txs) == 0:
self.context.logger.info("No profits to split, all transfer amounts are 0.")
return None
return txs

def _get_balance(self, address: str) -> Generator[None, None, Optional[int]]:
Expand Down Expand Up @@ -950,10 +955,11 @@ def _get_deliver_marketplace_tx(
"""Get the deliver tx for the marketplace delivery."""
contract_api_msg = yield from self.get_contract_api_response(
performative=ContractApiMessage.Performative.GET_STATE, # type: ignore
contract_address=self.params.mech_marketplace_address,
contract_address=task_data["mech_address"],
contract_id=str(AgentMechContract.contract_id),
contract_callable="get_deliver_to_market_tx",
request_id=task_data["request_id"],
sender_address=self.synchronized_data.safe_contract_address,
data=task_data["task_result"],
mech_staking_instance=self.params.mech_staking_instance_address,
mech_service_id=self.params.on_chain_service_id,
Expand All @@ -969,7 +975,6 @@ def _get_deliver_marketplace_tx(
data = cast(bytes, contract_api_msg.state.body["data"])
simulation_ok = cast(bool, contract_api_msg.state.body["simulation_ok"])

data = cast(bytes, contract_api_msg.state.body["data"])
return {
"to": task_data["mech_address"],
"value": ZERO_ETHER_VALUE,
Expand Down
7 changes: 5 additions & 2 deletions packages/valory/skills/task_submission_abci/rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,16 @@ class TaskSubmissionAbciApp(AbciApp[Event]):
Event.ROUND_TIMEOUT: 60.0,
}
cross_period_persisted_keys: FrozenSet[str] = frozenset(
[get_name(SynchronizedData.done_tasks)]
[
get_name(SynchronizedData.done_tasks),
get_name(SynchronizedData.final_tx_hash)
]
)
db_pre_conditions: Dict[AppState, Set[str]] = {
TaskPoolingRound: set(),
}
db_post_conditions: Dict[AppState, Set[str]] = {
FinishedTaskPoolingRound: {"most_voted_tx_hash"},
FinishedTaskPoolingRound: {"most_voted_tx_hash", "final_tx_hash"},
FinishedTaskExecutionWithErrorRound: set(),
FinishedWithoutTasksRound: set(),
}
2 changes: 1 addition & 1 deletion packages/valory/skills/task_submission_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fingerprint:
handlers.py: bafybeibe5n7my2vd2wlwo73sbma65epjqc7kxgtittewlylcmvnmoxtxzq
models.py: bafybeicoes4rtg2edxpdxlrow5dmnof2lm6xscagzp55mocrkbxy2xlxwe
payloads.py: bafybeia2yorri2u5rwh6vukb6iwdrbn53ygsuuhthns2txptvjipyb6f4e
rounds.py: bafybeicqimk23sc7itxwcu372lyerwnqly4v7tv2pcl4krd53gdizdv6ae
rounds.py: bafybeidsu5b2aa6zr2lu4tcp2bibah2inw7bibdt6pia5d2bv5uojz726a
tasks.py: bafybeicu5t5cvfhbndgpxbbtmp4vbmtyb6fba6vsnlewftvuderxp5lwcy
fingerprint_ignore_patterns: []
connections: []
Expand Down

0 comments on commit bead325

Please sign in to comment.