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

Dual staking #44

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
225c3ef
chore: dual staking token
jmoreira-valory Mar 5, 2025
c5e4667
[no ci] chore: update
jmoreira-valory Mar 5, 2025
1459ced
chore: update
jmoreira-valory Mar 6, 2025
0cf542f
[no ci] chore: update
jmoreira-valory Mar 6, 2025
451b3f5
[no ci] chore: update
jmoreira-valory Mar 6, 2025
235dcc2
chore: update
jmoreira-valory Mar 6, 2025
1eafff1
chore: add contract
jmoreira-valory Mar 6, 2025
54aebe8
fix: staking flow
jmoreira-valory Mar 6, 2025
a69aa86
fix: linters
jmoreira-valory Mar 6, 2025
6f81fde
[no ci] chore: update
jmoreira-valory Mar 10, 2025
d60c42e
chore: revert cli.py
jmoreira-valory Mar 10, 2025
0e068b2
chore: update refill requirements
jmoreira-valory Mar 10, 2025
7d25ee2
chore: refactor variables
jmoreira-valory Mar 10, 2025
799f309
chore: minor updates
jmoreira-valory Mar 10, 2025
a08958b
chore: remove test contract
jmoreira-valory Mar 10, 2025
7972fab
chore: update
jmoreira-valory Mar 10, 2025
096ba9a
fix: linters
jmoreira-valory Mar 10, 2025
469c596
Merge remote-tracking branch 'origin/HEAD' into feat/dual_staking
jmoreira-valory Mar 11, 2025
addd866
fix: manage.py
jmoreira-valory Mar 11, 2025
500fdba
chore: add missing file
jmoreira-valory Mar 11, 2025
0d20b8a
fix: output value
jmoreira-valory Mar 11, 2025
a39666c
fix: refill algorithm
jmoreira-valory Mar 12, 2025
2e77b1d
chore: fix tests
jmoreira-valory Mar 12, 2025
b41fc98
chore: improve readability
jmoreira-valory Mar 12, 2025
50d0c11
chore: doc
jmoreira-valory Mar 12, 2025
aeac99c
fix: catch general exception instead of contractlogicerror
jmoreira-valory Mar 12, 2025
7494bce
chore: add cache for staking params
jmoreira-valory Mar 12, 2025
e061edc
fix: linters
jmoreira-valory Mar 12, 2025
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
20 changes: 20 additions & 0 deletions operate/data/contracts/dual_staking_token/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2025 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------

"""This module contains the support resources for the dual staking contract."""
134 changes: 134 additions & 0 deletions operate/data/contracts/dual_staking_token/contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2025 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------

"""This module contains the class to connect to the `DualStakingToken` contract."""

from enum import Enum

from aea.common import JSONLike
from aea.configurations.base import PublicId
from aea.contracts.base import Contract
from aea.crypto.base import LedgerApi


class DualStakingTokenContract(Contract):
"""The Staking Token contract."""

contract_id = PublicId.from_str("valory/dual_staking_token:0.1.0")

@classmethod
def build_stake_tx(
cls,
ledger_api: LedgerApi,
contract_address: str,
service_id: int,
) -> JSONLike:
"""Build stake tx."""
contract_instance = cls.get_instance(ledger_api, contract_address)
data = contract_instance.encodeABI("stake", args=[service_id])
return dict(data=bytes.fromhex(data[2:]))

@classmethod
def build_checkpoint_tx(
cls,
ledger_api: LedgerApi,
contract_address: str,
) -> JSONLike:
"""Build checkpoint tx."""
contract_instance = cls.get_instance(ledger_api, contract_address)
data = contract_instance.encodeABI("checkpoint")
return dict(data=bytes.fromhex(data[2:]))

@classmethod
def build_unstake_tx(
cls,
ledger_api: LedgerApi,
contract_address: str,
service_id: int,
) -> JSONLike:
"""Build unstake tx."""
contract_instance = cls.get_instance(ledger_api, contract_address)
data = contract_instance.encodeABI("unstake", args=[service_id])
return dict(data=bytes.fromhex(data[2:]))

@classmethod
def num_services(
cls,
ledger_api: LedgerApi,
contract_address: str,
) -> JSONLike:
"""Retrieve the number of services."""
contract = cls.get_instance(ledger_api, contract_address)
num_services = contract.functions.numServices().call()
return dict(data=num_services)

@classmethod
def second_token(
cls,
ledger_api: LedgerApi,
contract_address: str,
) -> JSONLike:
"""Retrieve the second token."""
contract = cls.get_instance(ledger_api, contract_address)
second_token = contract.functions.secondToken().call()
return dict(data=second_token)

@classmethod
def second_token_amount(
cls,
ledger_api: LedgerApi,
contract_address: str,
) -> JSONLike:
"""Retrieve the second token amount."""
contract = cls.get_instance(ledger_api, contract_address)
second_token_amount = contract.functions.secondTokenAmount().call()
return dict(data=second_token_amount)

@classmethod
def reward_ratio(
cls,
ledger_api: LedgerApi,
contract_address: str,
) -> JSONLike:
"""Retrieve the reward ratio."""
contract = cls.get_instance(ledger_api, contract_address)
reward_ratio = contract.functions.rewardRatio().call()
return dict(data=reward_ratio)

@classmethod
def stake_ratio(
cls,
ledger_api: LedgerApi,
contract_address: str,
) -> JSONLike:
"""Retrieve the stake ratio."""
contract = cls.get_instance(ledger_api, contract_address)
stake_ratio = contract.functions.stakeRatio().call()
return dict(data=stake_ratio)

@classmethod
def staking_instance(
cls,
ledger_api: LedgerApi,
contract_address: str,
) -> JSONLike:
"""Retrieve the staking instance."""
contract = cls.get_instance(ledger_api, contract_address)
staking_instance = contract.functions.stakingInstance().call()
return dict(data=staking_instance)
23 changes: 23 additions & 0 deletions operate/data/contracts/dual_staking_token/contract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: dual_staking_token
author: valory
version: 0.1.0
type: contract
description: Dual staking token contract
license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeickx6ot3syhywbaewl3mmnowa75dd5rogqy7pmmc5ctk4yd74pvoa
build/DualStakingToken.json: bafybeibvh3lcvo242jqtyrfrbezgziedlymjlr7bmttvezhgjjxlgklcxa
contract.py: bafybeidb5b57xzx2sbfc25hnq4f3pabg66rnygivnihjigcllylavk344y
fingerprint_ignore_patterns: []
contracts: []
class_name: DualStakingTokenContract
contract_interface_paths:
ethereum: build/DualStakingToken.json
dependencies:
open-aea-ledger-ethereum:
version: <2,>=1.53.0
open-aea-test-autonomy:
version: <1,>=0.14.14.post1
web3:
version: <7,>=6.0.0
1 change: 1 addition & 0 deletions operate/ledger/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"meme_base_beta": "0x6011E09e7c095e76980b22498d69dF18EB62BeD8",
"meme_base_beta_2": "0xfb7669c3AdF673b3A545Fa5acd987dbfdA805e22",
"meme_base_beta_3": "0xCA61633b03c54F64b6A7F1f9A9C0A6Feb231Cc4D",
"dual_staking_testnet": "0xd64Cf67500b7d15A41E02DDeb40F3A73CB533eB5",
},
Chain.CELO: {
"meme_celo_alpha_2": "0x95D12D193d466237Bc1E92a1a7756e4264f574AB",
Expand Down
Loading