Skip to content

Commit

Permalink
[feat] Register chains and tokens through precompile (ExocoreNetwork#116
Browse files Browse the repository at this point in the history
)

* add register client chain and tokens in precompile

* fix the issues identified by code review in#PR116

* finalized the precompile for token and client chain registeration

* rename RegisterTokens to RegisterToken and fix the check for the *big.int in the precompile

* update go-getter to fix the go vulnerability
  • Loading branch information
TimmyExogenous authored Jul 4, 2024
1 parent 106fb18 commit 13c0a1b
Show file tree
Hide file tree
Showing 31 changed files with 799 additions and 358 deletions.
5 changes: 5 additions & 0 deletions local_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
jq '.consensus_params["block"]["max_gas"]="10000000"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

# x/assets
# Using the local funding address as the Exocore gateway address to facilitate testing for precompiles without depending on the gateway contract.
jq '.app_state["assets"]["params"]["exocore_lz_app_address"]="0x3e108c058e8066da635321dc3018294ca82ddedf"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["assets"]["client_chains"][0]["name"]="Example EVM chain"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["assets"]["client_chains"][0]["meta_info"]="Example EVM chain meta info"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["assets"]["client_chains"][0]["layer_zero_chain_id"]="101"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["assets"]["client_chains"][0]["address_length"]="20"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["assets"]["tokens"][0]["asset_basic_info"]["name"]="Tether USD"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["assets"]["tokens"][0]["asset_basic_info"]["meta_info"]="Tether USD token"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["assets"]["tokens"][0]["asset_basic_info"]["address"]="0xdAC17F958D2ee523a2206206994597C13D831ec7"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["assets"]["tokens"][0]["asset_basic_info"]["layer_zero_chain_id"]="101"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["assets"]["tokens"][0]["asset_basic_info"]["total_supply"]="40022689732746729"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
Expand Down
83 changes: 57 additions & 26 deletions precompiles/assets/IAssets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,77 @@ pragma solidity >=0.8.17;
address constant ASSETS_PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000804;

/// @dev The Assets contract's instance.
IAssets constant ASSETS_CONTRACT = IAssets(
ASSETS_PRECOMPILE_ADDRESS
);
IAssets constant ASSETS_CONTRACT = IAssets(ASSETS_PRECOMPILE_ADDRESS);

/// @author Exocore Team
/// @title Assets Precompile Contract
/// @dev The interface through which solidity contracts will interact with assets module
/// @custom:address 0x0000000000000000000000000000000000000804
interface IAssets {
/// TRANSACTIONS
/// @dev deposit the client chain assets for the staker,
/// that will change the state in deposit module
/// Note that this address cannot be a module account.
/// @param clientChainLzID The LzID of client chain
/// @param assetsAddress The client chain asset address
/// @param stakerAddress The staker address
/// @param opAmount The amount to deposit

/// TRANSACTIONS
/// @dev deposit the client chain assets for the staker,
/// that will change the state in deposit module
/// Note that this address cannot be a module account.
/// @param clientChainID is the layerZero chainID if it is supported.
// It might be allocated by Exocore when the client chain isn't supported
// by layerZero
/// @param assetsAddress The client chain asset address
/// @param stakerAddress The staker address
/// @param opAmount The amount to deposit
function depositTo(
uint32 clientChainLzID,
uint32 clientChainID,
bytes memory assetsAddress,
bytes memory stakerAddress,
uint256 opAmount
) external returns (bool success, uint256 latestAssetState);
uint256 opAmount) external
returns (bool success, uint256 latestAssetState);

/// TRANSACTIONS
/// @dev withdraw To the staker, that will change the state in withdraw module
/// Note that this address cannot be a module account.
/// @param clientChainLzID The LzID of client chain
/// @param assetsAddress The client chain asset Address
/// @param withdrawAddress The withdraw address
/// @param opAmount The withdraw amount
/// TRANSACTIONS
/// @dev withdraw To the staker, that will change the state in withdraw module
/// Note that this address cannot be a module account.
/// @param clientChainID is the layerZero chainID if it is supported.
// It might be allocated by Exocore when the client chain isn't supported
// by layerZero
/// @param assetsAddress The client chain asset Address
/// @param withdrawAddress The withdraw address
/// @param opAmount The withdraw amount
function withdrawPrincipal(
uint32 clientChainLzID,
uint32 clientChainID,
bytes memory assetsAddress,
bytes memory withdrawAddress,
uint256 opAmount
) external returns (bool success, uint256 latestAssetState);

/// QUERIES
/// @dev Returns the chain indices of the client chains.
function getClientChains() external view returns (bool, uint32[] memory);
}
/// TRANSACTIONS
/// @dev register some client chain to allow token registration from that chain, staking
/// from that chain, and other operations from that chain.
/// @param clientChainID is the layerZero chainID if it is supported.
// It might be allocated by Exocore when the client chain isn't supported
// by layerZero
function registerClientChain(
uint32 clientChainID,
uint8 addressLength,
string calldata name,
string calldata metaInfo,
string calldata signatureType
) external returns (bool success);

/// TRANSACTIONS
/// @dev register unwhitelisted token addresses to exocore
/// @param clientChainID is the layerZero chainID if it is supported.
// It might be allocated by Exocore when the client chain isn't supported
// by layerZero
/// @param token The token addresses that would be registered to exocore
function registerToken(
uint32 clientChainID,
bytes calldata token,
uint8 decimals,
uint256 tvlLimit,
string calldata name,
string calldata metaData
) external returns (bool success);

/// QUERIES
/// @dev Returns the chain indices of the client chains.
function getClientChains() external view returns (bool, uint32[] memory);
}
182 changes: 137 additions & 45 deletions precompiles/assets/abi.json
Original file line number Diff line number Diff line change
@@ -1,98 +1,190 @@
[
{
"type": "function",
"name": "depositTo",
"inputs": [
"inputs":
[
{
"name": "clientChainLzID",
"type": "uint32",
"internalType": "uint32"
"internalType": "uint32",
"name": "clientChainID",
"type": "uint32"
},
{
"internalType": "bytes",
"name": "assetsAddress",
"type": "bytes",
"internalType": "bytes"
"type": "bytes"
},
{
"internalType": "bytes",
"name": "stakerAddress",
"type": "bytes",
"internalType": "bytes"
"type": "bytes"
},
{
"internalType": "uint256",
"name": "opAmount",
"type": "uint256",
"internalType": "uint256"
"type": "uint256"
}
],
"outputs": [
"name": "depositTo",
"outputs":
[
{
"internalType": "bool",
"name": "success",
"type": "bool",
"internalType": "bool"
"type": "bool"
},
{
"internalType": "uint256",
"name": "latestAssetState",
"type": "uint256",
"internalType": "uint256"
"type": "uint256"
}
],
"stateMutability": "nonpayable"
"stateMutability": "nonpayable",
"type": "function"
},
{
"type": "function",
"name": "getClientChains",
"inputs": [],
"outputs": [
"name": "getClientChains",
"outputs":
[
{
"internalType": "bool",
"name": "",
"type": "bool",
"internalType": "bool"
"type": "bool"
},
{
"internalType": "uint32[]",
"name": "",
"type": "uint32[]",
"internalType": "uint32[]"
"type": "uint32[]"
}
],
"stateMutability": "view"
"stateMutability": "view",
"type": "function"
},
{
"type": "function",
"name": "withdrawPrincipal",
"inputs": [
"inputs":
[
{
"internalType": "uint32",
"name": "clientChainID",
"type": "uint32"
},
{
"internalType": "uint8",
"name": "addressLength",
"type": "uint8"
},
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "metaInfo",
"type": "string"
},
{
"internalType": "string",
"name": "signatureType",
"type": "string"
}
],
"name": "registerClientChain",
"outputs":
[
{
"internalType": "bool",
"name": "success",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs":
[
{
"internalType": "uint32",
"name": "clientChainID",
"type": "uint32"
},
{
"name": "clientChainLzID",
"type": "uint32",
"internalType": "uint32"
"internalType": "bytes",
"name": "token",
"type": "bytes"
},
{
"internalType": "uint8",
"name": "decimals",
"type": "uint8"
},
{
"internalType": "uint256",
"name": "tvlLimit",
"type": "uint256"
},
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "metaData",
"type": "string"
}
],
"name": "registerToken",
"outputs":
[
{
"internalType": "bool",
"name": "success",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs":
[
{
"internalType": "uint32",
"name": "clientChainID",
"type": "uint32"
},
{
"internalType": "bytes",
"name": "assetsAddress",
"type": "bytes",
"internalType": "bytes"
"type": "bytes"
},
{
"internalType": "bytes",
"name": "withdrawAddress",
"type": "bytes",
"internalType": "bytes"
"type": "bytes"
},
{
"internalType": "uint256",
"name": "opAmount",
"type": "uint256",
"internalType": "uint256"
"type": "uint256"
}
],
"outputs": [
"name": "withdrawPrincipal",
"outputs":
[
{
"internalType": "bool",
"name": "success",
"type": "bool",
"internalType": "bool"
"type": "bool"
},
{
"internalType": "uint256",
"name": "latestAssetState",
"type": "uint256",
"internalType": "uint256"
"type": "uint256"
}
],
"stateMutability": "nonpayable"
"stateMutability": "nonpayable",
"type": "function"
}
]
]
Loading

0 comments on commit 13c0a1b

Please sign in to comment.