Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/sell #350

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d841608
feat/add sell outcome token feature
annasambrook Nov 7, 2024
501b33d
fix error in reported message
annasambrook Nov 12, 2024
65cb73a
add return amount and sell outcome token round
annasambrook Nov 13, 2024
b7e7a51
chore: generators
annasambrook Nov 13, 2024
a50ecad
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/sell
annasambrook Nov 13, 2024
1284dfb
chore: generators
annasambrook Nov 13, 2024
7cf0997
make requested changes
annasambrook Nov 15, 2024
4188687
Merge remote-tracking branch 'refs/remotes/origin/hotfix/staking-kpi-…
annasambrook Nov 22, 2024
104de4f
make suggested changes
annasambrook Nov 22, 2024
e35ce11
chore: generators
annasambrook Nov 22, 2024
1711625
fix: change copyright date
annasambrook Nov 22, 2024
502897e
chore: generators
annasambrook Nov 22, 2024
32fb70d
Merge branch 'refs/heads/hotfix/staking-kpi-reachability' into feat/sell
annasambrook Dec 5, 2024
445998e
add: previous_vote and sell logic
annasambrook Dec 5, 2024
fe78d74
add: initial fsm changes to include sell outcome token round
annasambrook Dec 5, 2024
3fd007f
chore: generators
annasambrook Dec 5, 2024
5e0524c
fix: copyright date
annasambrook Dec 6, 2024
6f47bf1
Merge branch 'hotfix/staking-kpi-reachability' into feat/sell
Adamantios Dec 6, 2024
b65ba87
chore: ignore bandit's false positive error
Adamantios Dec 6, 2024
e9ba6ee
chore: run generators
Adamantios Dec 6, 2024
a3aae14
feat: update the bets so that we store investments per vote
Adamantios Dec 6, 2024
89cd038
chore: create an action to enforce a merge rule for `main`
Adamantios Dec 6, 2024
cf12051
Merge pull request #367 from valory-xyz/feat/bets-structure
Adamantios Dec 9, 2024
3dc7f7e
Merge remote-tracking branch 'origin/feat/sell' into feat/sell
annasambrook Dec 9, 2024
2709c8c
fix: approval tx status
annasambrook Dec 9, 2024
f919d2e
fix: build approval tx
annasambrook Dec 9, 2024
0a5fc2c
fix: make return amount property
annasambrook Dec 9, 2024
d0e3497
fix: build approval tx token
annasambrook Dec 9, 2024
2f0afa2
fix: remove is wxdai check
annasambrook Dec 9, 2024
87d1205
chore: generators
annasambrook Dec 9, 2024
79191b9
Merge branch 'refs/heads/hotfix/staking-kpi-reachability' into feat/sell
annasambrook Dec 9, 2024
2e90b9e
chore: generators
annasambrook Dec 9, 2024
cdfa138
chore: generators
annasambrook Dec 9, 2024
d234b5e
Update packages/valory/skills/decision_maker_abci/behaviours/bet_plac…
annasambrook Dec 9, 2024
235881b
Update packages/valory/skills/decision_maker_abci/behaviours/bet_plac…
annasambrook Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/merge_rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'Check Branch'

on:
pull_request:

jobs:
check_branch:
runs-on: ubuntu-latest
steps:
- name: Check branch
if: github.base_ref == 'main' && github.head_ref != 'develop'
run: |
echo "ERROR: You can only merge to main from develop."
exit 1
16 changes: 8 additions & 8 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"custom/jhehemann/kelly_criterion/0.1.0": "bafybeif55cu7cf6znyma7kxus4wxa2doarhau2xmndo57iegshxorivwmq",
"custom/w1kke/always_blue/0.1.0": "bafybeieshu32h3es2fslduuhr7nimuvh2vuibyeqdunzrcggaeohekg3jm",
"custom/valory/kelly_criterion_no_conf/0.1.0": "bafybeibxfp27rzrfnp7sxq62vwv32pdvrijxi7vzg7ihukkaka3bwzrgae",
"contract/valory/market_maker/0.1.0": "bafybeihrz4q5ia7jnflsv2myg6kkung2dfiogqrevuy7xlmqws7tr27rdi",
"contract/valory/market_maker/0.1.0": "bafybeibevdc5trbi2qgt2tvwbsr2h5xvonfhcjwfmozftzvef575fdvbjq",
"contract/valory/realitio/0.1.0": "bafybeietgux6kkhdquspy35qera7gjwwqwrremmoeatjzwwokjb2lzsata",
"contract/valory/realitio_proxy/0.1.0": "bafybeidx37xzjjmapwacedgzhum6grfzhp5vhouz4zu3pvpgdy5pgb2fr4",
"contract/valory/conditional_tokens/0.1.0": "bafybeibnzmqmeph4cj5vfh3s622mo2o5627vjjwc6bptrhj4dk65mzgvhe",
Expand All @@ -15,15 +15,15 @@
"contract/valory/mech_activity/0.1.0": "bafybeibmqmle5fnal3gxlpdmcos2kogzra4q3pr3o5nh7shplxuilji3t4",
"contract/valory/staking_token/0.1.0": "bafybeiep4r6qyilbfgzdvx6t7zvpgaioxqktmxm7puwtnbpb2ftlib43gy",
"contract/valory/relayer/0.1.0": "bafybeicawmds6czx7db2lcktvexwrp245jpekgulndtos5s5zdid3ilvq4",
"skill/valory/market_manager_abci/0.1.0": "bafybeigmclk3pe3h2b57kcem4xlhkfgca5sosbstyqqoq6pnkt7uuhzvwi",
"skill/valory/decision_maker_abci/0.1.0": "bafybeifineeaqixdqafihy5ch2gmuq2pyb7xdcxychfbypfpz344nc3j4e",
"skill/valory/trader_abci/0.1.0": "bafybeieauih4nqotqjiamd2mrehjvxxbq7astbt2ypnltokhkvdjqzrkkm",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeie433saaj7gn6ronam3eaaneqnr6fjcjnpchkswqjye2jfv5rntfi",
"skill/valory/market_manager_abci/0.1.0": "bafybeiflzhfmpma7upnfas7faesmbeahack2gqnz6tvyx3hd7ggrk6c7ie",
"skill/valory/decision_maker_abci/0.1.0": "bafybeicxivbaudftt5pyjinxxcyfol2cjqxfzphl6qaolgyf55dflzcxha",
"skill/valory/trader_abci/0.1.0": "bafybeib4rakcrqp47grlhgcswi6q2zo5rha5nuskidpfgfvitdbotar2j4",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeicgs7q5gttstxb25th27nncieku3etmmab4ewtdkozuaswz67k3w4",
"skill/valory/staking_abci/0.1.0": "bafybeibjgipzfle3b2gtuh42u2y6umgf47a5qrdtbvni46tox4lgv6wm4i",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeier2qz5xkiha5krgav7hfrxvb5666csxyko4drfgouj5htjmmvwni",
"agent/valory/trader/0.1.0": "bafybeidedkcb7vbbu5stg5rpajlwq4h5wtuhdygvmfgtbvgpwttrs6frve",
"service/valory/trader/0.1.0": "bafybeigmu3xk233huyc7i7on7fqrkke2piijnd5ijwvsstt45vez4tno5a",
"service/valory/trader_pearl/0.1.0": "bafybeifxmmnkpg6d7ka7tlurzm5vuzaxiurdoxgoqydr7ksjkzpngpn7cy"
"agent/valory/trader/0.1.0": "bafybeietht7fwg2gvwtbwmtwny2haobearktv42xyjencolxregostynba",
"service/valory/trader/0.1.0": "bafybeifka4fszmveucfuefdp7lzttlb5iad5s5u34cao3bllzmdgdjhoay",
"service/valory/trader_pearl/0.1.0": "bafybeidwhdkyilx4ub4pzme2l5w5v4nhafrttk7n4b74jyil4a57j3kjnq"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
Expand Down
10 changes: 5 additions & 5 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contracts:
- valory/gnosis_safe:0.1.0:bafybeih3ropivth4wn7zbzudisx3qezbht5jyndd4w7az7fq634lpozoge
- valory/gnosis_safe_proxy_factory:0.1.0:bafybeieg57u3z7cdlmdamad5e6lk7kmsli2zurzkg3sl4y7lhekcu4y3au
- valory/service_registry:0.1.0:bafybeiaop64kwdoetxtedoehabmsalojmms7ihuoqcdwxtwb2hk5i6bzye
- valory/market_maker:0.1.0:bafybeihrz4q5ia7jnflsv2myg6kkung2dfiogqrevuy7xlmqws7tr27rdi
- valory/market_maker:0.1.0:bafybeibevdc5trbi2qgt2tvwbsr2h5xvonfhcjwfmozftzvef575fdvbjq
- valory/multisend:0.1.0:bafybeig5byt5urg2d2bsecufxe5ql7f4mezg3mekfleeh32nmuusx66p4y
- valory/mech:0.1.0:bafybeiejfjfoxqggghcme43sx53q5gruefrws3k2jam2opkxl5uzffoarm
- valory/conditional_tokens:0.1.0:bafybeibnzmqmeph4cj5vfh3s622mo2o5627vjjwc6bptrhj4dk65mzgvhe
Expand All @@ -45,10 +45,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeigrdlxed3xlsnxtjhnsbl3cojruihxcqx4jxhgivkd5i2fkjncgba
- valory/termination_abci:0.1.0:bafybeib5l7jhew5ic6iq24dd23nidcoimzqkrk556gqywhoziatj33zvwm
- valory/transaction_settlement_abci:0.1.0:bafybeic7q7recyka272udwcupblwbkc3jkodgp74fvcdxb7urametg5dae
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeie433saaj7gn6ronam3eaaneqnr6fjcjnpchkswqjye2jfv5rntfi
- valory/market_manager_abci:0.1.0:bafybeigmclk3pe3h2b57kcem4xlhkfgca5sosbstyqqoq6pnkt7uuhzvwi
- valory/decision_maker_abci:0.1.0:bafybeifineeaqixdqafihy5ch2gmuq2pyb7xdcxychfbypfpz344nc3j4e
- valory/trader_abci:0.1.0:bafybeieauih4nqotqjiamd2mrehjvxxbq7astbt2ypnltokhkvdjqzrkkm
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeicgs7q5gttstxb25th27nncieku3etmmab4ewtdkozuaswz67k3w4
- valory/market_manager_abci:0.1.0:bafybeiflzhfmpma7upnfas7faesmbeahack2gqnz6tvyx3hd7ggrk6c7ie
- valory/decision_maker_abci:0.1.0:bafybeicxivbaudftt5pyjinxxcyfol2cjqxfzphl6qaolgyf55dflzcxha
- valory/trader_abci:0.1.0:bafybeib4rakcrqp47grlhgcswi6q2zo5rha5nuskidpfgfvitdbotar2j4
- valory/staking_abci:0.1.0:bafybeibjgipzfle3b2gtuh42u2y6umgf47a5qrdtbvni46tox4lgv6wm4i
- valory/check_stop_trading_abci:0.1.0:bafybeier2qz5xkiha5krgav7hfrxvb5666csxyko4drfgouj5htjmmvwni
- valory/mech_interact_abci:0.1.0:bafybeid6m3i5ofq7vuogqapdnoshhq7mswmudhvfcr2craw25fdwtoe3lm
Expand Down
53 changes: 52 additions & 1 deletion packages/valory/contracts/market_maker/contract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2023 Valory AG
# Copyright 2024 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -133,3 +133,54 @@ def get_buy_data(
outcomeIndex=outcome_index,
minOutcomeTokensToBuy=min_outcome_tokens_to_buy,
)

@classmethod
def calc_sell_amount(
cls,
ledger_api: EthereumApi,
contract_address: str,
return_amount: int,
outcome_index: int,
) -> JSONLike:
"""
Calculate the buy amount.

:param ledger_api: the ledger API object
:param contract_address: the contract address
:param return_amount: the amount the user will have returned
:param outcome_index: the index of the answer's outcome that the user wants to sell for
:return: the outcomeTokenSellAmount
"""
outcome_token_sell_amount = cls._method_call(
ledger_api,
contract_address,
"calcSellAmount",
returnAmount=return_amount,
outcomeIndex=outcome_index,
)
return dict(outcomeTokenSellAmount=outcome_token_sell_amount)

def get_sell_data(
cls,
ledger_api: LedgerApi,
contract_address: str,
return_amount: int,
outcome_index: int,
max_outcome_tokens_to_sell: int,
) -> Dict[str, bytes]:
"""Gets the encoded arguments for a sell tx, which should only be called via the multisig.

:param ledger_api: the ledger API object
:param contract_address: the contract address
:param return_amount: the amount the user have returned
:param outcome_index: the index of the answer's outcome that the user wants to sell tokens for
:param max_outcome_tokens_to_sell: the output of the `calcSellAmount` contract method
"""
return cls._encode_abi(
ledger_api,
contract_address,
"sell",
returnAmount=return_amount,
outcomeIndex=outcome_index,
maxOutcomeTokenSellAmount=max_outcome_tokens_to_sell,
)
2 changes: 1 addition & 1 deletion packages/valory/contracts/market_maker/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fingerprint:
README.md: bafybeiegnihrovfkk5big52pl4bo6evt5toqvvmft2jgnq6ofdbhfp7xwa
__init__.py: bafybeicoucixii3fv5xlpk3zfewm4ys4okidcng54bhtjxvwup7g2jcjza
build/FixedProductMarketMaker.json: bafybeigim7n3f67r5czfc5wp2m7cxzxwvnhxops3n5j2zlawenan7qrrtu
contract.py: bafybeicfiicuke4ly5hpcxtyvnob5bgzrqsopuxalruxp2m3w4koxmhrqa
contract.py: bafybeifcopgnnts3dbfh636vvdsgporlkt2olwr2iwuwaom5vjcrtbe5wi
fingerprint_ignore_patterns: []
contracts: []
class_name: FixedProductMarketMakerContract
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeidedkcb7vbbu5stg5rpajlwq4h5wtuhdygvmfgtbvgpwttrs6frve
agent: valory/trader:0.1.0:bafybeietht7fwg2gvwtbwmtwny2haobearktv42xyjencolxregostynba
number_of_agents: 4
deployment:
agent:
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader_pearl/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeibg7bdqpioh4lmvknw3ygnllfku32oca4eq5pqtvdrdsgw6buko7e
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeidedkcb7vbbu5stg5rpajlwq4h5wtuhdygvmfgtbvgpwttrs6frve
agent: valory/trader:0.1.0:bafybeietht7fwg2gvwtbwmtwny2haobearktv42xyjencolxregostynba
number_of_agents: 1
deployment:
agent:
Expand Down
40 changes: 36 additions & 4 deletions packages/valory/skills/decision_maker_abci/behaviours/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from aea.configurations.data_types import PublicId
from aea.protocols.base import Message
from aea.protocols.dialogue.base import Dialogue
from hexbytes import HexBytes

from packages.valory.contracts.erc20.contract import ERC20
from packages.valory.contracts.gnosis_safe.contract import (
Expand Down Expand Up @@ -354,12 +355,14 @@ def check_balance(self) -> WaitableConditionType:
def update_bet_transaction_information(self) -> None:
"""Get whether the bet's invested amount should be updated."""
sampled_bet = self.sampled_bet
# Update the bet's invested amount, the new bet amount is added to previously invested amount
sampled_bet.invested_amount += self.synchronized_data.bet_amount

# Update the bet's invested amount
updated = sampled_bet.update_investments(self.synchronized_data.bet_amount)
if not updated:
self.context.logger.error("Could not update the investments!")

# Update bet transaction timestamp
sampled_bet.processed_timestamp = self.synced_timestamp
# update no of bets made
sampled_bet.n_bets += 1
# Update Queue number for priority logic
sampled_bet.queue_status = sampled_bet.queue_status.next_status()

Expand Down Expand Up @@ -719,6 +722,35 @@ def finish_behaviour(self, payload: BaseTxPayload) -> Generator:

self.set_done()

def build_approval_tx(
self, amount: int, spender: str, token: str
) -> WaitableConditionType:
"""Build an ERC20 approve transaction."""
response_msg = yield from self.get_contract_api_response(
performative=ContractApiMessage.Performative.GET_STATE, # type: ignore
contract_address=self.collateral_token,
contract_id=str(ERC20.contract_id),
contract_callable="build_approval_tx",
spender=spender,
amount=amount,
)

if response_msg.performative != ContractApiMessage.Performative.STATE:
self.context.logger.info(f"Could not build approval tx: {response_msg}")
return False

approval_data = response_msg.state.body.get("data")
if approval_data is None:
self.context.logger.info(f"Could not build approval tx: {response_msg}")
return False

batch = MultisendBatch(
to=token,
data=HexBytes(approval_data),
)
self.multisend_batches.append(batch)
return True


class BaseSubscriptionBehaviour(DecisionMakerBaseBehaviour, ABC):
"""Base class for subscription behaviours."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,12 @@ def _build_exchange_tx(self) -> WaitableConditionType:

def _build_approval_tx(self) -> WaitableConditionType:
"""Build an ERC20 approve transaction."""
response_msg = yield from self.get_contract_api_response(
performative=ContractApiMessage.Performative.GET_STATE, # type: ignore
contract_address=self.collateral_token,
contract_id=str(ERC20.contract_id),
contract_callable="build_approval_tx",
spender=self.market_maker_contract_address,
amount=self.investment_amount,
approval_tx = yield from self.build_approval_tx(
self.investment_amount,
self.market_maker_contract_address,
self.collateral_token,
annasambrook marked this conversation as resolved.
Show resolved Hide resolved
)

if response_msg.performative != ContractApiMessage.Performative.STATE:
self.context.logger.info(f"Could not build approval tx: {response_msg}")
return False

approval_data = response_msg.state.body.get("data")
if approval_data is None:
self.context.logger.info(f"Could not build approval tx: {response_msg}")
return False

batch = MultisendBatch(
to=self.collateral_token,
data=HexBytes(approval_data),
)
self.multisend_batches.append(batch)
return True
return approval_tx
annasambrook marked this conversation as resolved.
Show resolved Hide resolved

def _calc_buy_amount(self) -> WaitableConditionType:
"""Calculate the buy amount of the conditional token."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,6 @@ def _update_selected_bet(
self.context.logger.info(
f"with the timestamp:{datetime.fromtimestamp(active_sampled_bet.processed_timestamp)}"
)
if prediction_response is not None:
active_sampled_bet.n_bets += 1

self.store_bets()

Expand Down
Loading