Skip to content

Commit

Permalink
F/rewards distribution send (#96)
Browse files Browse the repository at this point in the history
#97 follow-up. Send rewards along with the distribution table using ICS-20 with a json payload in the Memo field
  • Loading branch information
maurolacy authored Jan 4, 2025
1 parent 3e9f03d commit 9fdc9a1
Show file tree
Hide file tree
Showing 45 changed files with 1,160 additions and 77 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ babylon-btcstaking = { path = "./packages/btcstaking" }
babylon-contract = { path = "./contracts/babylon" }
eots = { path = "./packages/eots" }
anyhow = "1.0.82"
bech32 = "0.9.1"
bitcoin = "0.31.1"
bitvec = "1"
bech32 = "0.9.1"
blst = "0.3.11"
cosmos-sdk-proto = { version = "0.19.0", default-features = false, features = [
"cosmwasm",
Expand Down
1 change: 1 addition & 0 deletions contracts/babylon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ cosmos-sdk-proto = { workspace = true }
thiserror = { workspace = true }
prost = { workspace = true }
ics23 = { workspace = true }
sha2 = { workspace = true }

[dev-dependencies]
babylon-bindings-test = { path = "../../packages/bindings-test" }
Expand Down
1 change: 1 addition & 0 deletions contracts/babylon/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub fn setup_instance() -> Instance<MockApi, MockStorage, MockQuerier> {
btc_finality_code_id: None,
btc_finality_msg: None,
admin: None,
transfer_info: None,
};
let info = mock_info(CREATOR, &[]);
let res: Response = instantiate(&mut deps, mock_env(), info, msg).unwrap();
Expand Down
154 changes: 154 additions & 0 deletions contracts/babylon/schema/babylon-contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@
"notify_cosmos_zone": {
"description": "notify_cosmos_zone indicates whether to send Cosmos zone messages notifying BTC-finalised headers. NOTE: If set to true, then the Cosmos zone needs to integrate the corresponding message handler as well",
"type": "boolean"
},
"transfer_info": {
"description": "IBC information for ICS-020 rewards transfer. If not set, distributed rewards will be native to the Consumer",
"anyOf": [
{
"$ref": "#/definitions/IbcTransferInfo"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false,
Expand All @@ -103,6 +114,22 @@
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>. See also <https://github.com/CosmWasm/cosmwasm/blob/main/docs/MESSAGE_TYPES.md>.",
"type": "string"
},
"IbcTransferInfo": {
"type": "object",
"required": [
"channel_id",
"recipient"
],
"properties": {
"channel_id": {
"type": "string"
},
"recipient": {
"$ref": "#/definitions/Recipient"
}
},
"additionalProperties": false
},
"Network": {
"type": "string",
"enum": [
Expand All @@ -111,6 +138,34 @@
"signet",
"regtest"
]
},
"Recipient": {
"oneOf": [
{
"type": "object",
"required": [
"contract_addr"
],
"properties": {
"contract_addr": {
"type": "string"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"module_addr"
],
"properties": {
"module_addr": {
"type": "string"
}
},
"additionalProperties": false
}
]
}
}
},
Expand Down Expand Up @@ -164,6 +219,32 @@
}
},
"additionalProperties": false
},
{
"description": "`SendRewards` is a message sent by the finality contract, to send rewards to Babylon",
"type": "object",
"required": [
"send_rewards"
],
"properties": {
"send_rewards": {
"type": "object",
"required": [
"fp_distribution"
],
"properties": {
"fp_distribution": {
"description": "`fp_distribution` is the list of finality providers and their rewards",
"type": "array",
"items": {
"$ref": "#/definitions/RewardsDistribution"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"definitions": {
Expand Down Expand Up @@ -287,6 +368,26 @@
}
},
"additionalProperties": false
},
"RewardsDistribution": {
"type": "object",
"required": [
"fp_pubkey_hex",
"reward"
],
"properties": {
"fp_pubkey_hex": {
"type": "string"
},
"reward": {
"$ref": "#/definitions/Uint128"
}
},
"additionalProperties": false
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
},
Expand Down Expand Up @@ -533,6 +634,20 @@
}
},
"additionalProperties": false
},
{
"description": "TransferInfo returns the IBC transfer information stored in the contract for ICS-020 rewards transfer. If not set, distributed rewards are native to the Consumer",
"type": "object",
"required": [
"transfer_info"
],
"properties": {
"transfer_info": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
]
},
Expand Down Expand Up @@ -1286,6 +1401,7 @@
"babylon_tag",
"btc_confirmation_depth",
"checkpoint_finalization_timeout",
"denom",
"network",
"notify_cosmos_zone"
],
Expand Down Expand Up @@ -1344,6 +1460,9 @@
"null"
]
},
"denom": {
"type": "string"
},
"network": {
"$ref": "#/definitions/Network"
},
Expand Down Expand Up @@ -1522,6 +1641,41 @@
"type": "string"
}
}
},
"transfer_info": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Nullable_TransferInfo",
"anyOf": [
{
"$ref": "#/definitions/TransferInfo"
},
{
"type": "null"
}
],
"definitions": {
"TransferInfo": {
"description": "IBC transfer (ICS-020) channel settings",
"type": "object",
"required": [
"address_type",
"channel_id",
"to_address"
],
"properties": {
"address_type": {
"type": "string"
},
"channel_id": {
"type": "string"
},
"to_address": {
"type": "string"
}
},
"additionalProperties": false
}
}
}
}
}
46 changes: 46 additions & 0 deletions contracts/babylon/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@
}
},
"additionalProperties": false
},
{
"description": "`SendRewards` is a message sent by the finality contract, to send rewards to Babylon",
"type": "object",
"required": [
"send_rewards"
],
"properties": {
"send_rewards": {
"type": "object",
"required": [
"fp_distribution"
],
"properties": {
"fp_distribution": {
"description": "`fp_distribution` is the list of finality providers and their rewards",
"type": "array",
"items": {
"$ref": "#/definitions/RewardsDistribution"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"definitions": {
Expand Down Expand Up @@ -171,6 +197,26 @@
}
},
"additionalProperties": false
},
"RewardsDistribution": {
"type": "object",
"required": [
"fp_pubkey_hex",
"reward"
],
"properties": {
"fp_pubkey_hex": {
"type": "string"
},
"reward": {
"$ref": "#/definitions/Uint128"
}
},
"additionalProperties": false
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
}
55 changes: 55 additions & 0 deletions contracts/babylon/schema/raw/instantiate.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@
"notify_cosmos_zone": {
"description": "notify_cosmos_zone indicates whether to send Cosmos zone messages notifying BTC-finalised headers. NOTE: If set to true, then the Cosmos zone needs to integrate the corresponding message handler as well",
"type": "boolean"
},
"transfer_info": {
"description": "IBC information for ICS-020 rewards transfer. If not set, distributed rewards will be native to the Consumer",
"anyOf": [
{
"$ref": "#/definitions/IbcTransferInfo"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false,
Expand All @@ -99,6 +110,22 @@
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>. See also <https://github.com/CosmWasm/cosmwasm/blob/main/docs/MESSAGE_TYPES.md>.",
"type": "string"
},
"IbcTransferInfo": {
"type": "object",
"required": [
"channel_id",
"recipient"
],
"properties": {
"channel_id": {
"type": "string"
},
"recipient": {
"$ref": "#/definitions/Recipient"
}
},
"additionalProperties": false
},
"Network": {
"type": "string",
"enum": [
Expand All @@ -107,6 +134,34 @@
"signet",
"regtest"
]
},
"Recipient": {
"oneOf": [
{
"type": "object",
"required": [
"contract_addr"
],
"properties": {
"contract_addr": {
"type": "string"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"module_addr"
],
"properties": {
"module_addr": {
"type": "string"
}
},
"additionalProperties": false
}
]
}
}
}
Loading

0 comments on commit 9fdc9a1

Please sign in to comment.