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: its hub support #87

Merged
merged 94 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
7f6cee4
saving progress
Foivos Jun 5, 2024
6e5acdb
Merge remote-tracking branch 'origin/main' into feat/script-utils
Foivos Jun 6, 2024
296eece
added the transaction builder
Foivos Jun 6, 2024
edeeb38
lint and prettier
Foivos Jun 6, 2024
974192d
added object cache
Foivos Jun 7, 2024
5d3543c
fixed some bugs
Foivos Jun 7, 2024
e943312
empty commit
Foivos Jun 7, 2024
9b6be0f
added some structs, adding squid structs next
Foivos Jun 7, 2024
8d623d5
Merge branch 'main' into feat/script-utils
milapsheth Jun 7, 2024
5432896
added all the move types
Foivos Jun 11, 2024
6a8d79b
fix an error
Foivos Jun 11, 2024
36c43a7
prettier
Foivos Jun 11, 2024
8ba2aa9
adding publish options in TxBuilder
Foivos Jun 12, 2024
17600af
fixed some issues after testing
Foivos Jun 14, 2024
fc0acac
add ts of relevant utils
Foivos Jun 14, 2024
0cc49ca
use npx tsc instead
Foivos Jun 17, 2024
6c387bf
run compile properly
Foivos Jun 17, 2024
372514b
remove previous scripts
Foivos Jun 17, 2024
75397e4
add an index.ts
Foivos Jun 17, 2024
89205ae
fix imports
Foivos Jun 17, 2024
59237d4
update bcs pure types
Foivos Jun 17, 2024
cb32ea8
remove last change as it does not work
Foivos Jun 17, 2024
f192b36
add address to bcs
Foivos Jun 17, 2024
517aebb
Merge remote-tracking branch 'origin/main' into feat/script-utils
Foivos Jun 18, 2024
bc6ecc2
shorten typeName calculation as per euro's request
Foivos Jun 18, 2024
1edfffb
prettier
Foivos Jun 18, 2024
4f3aa9e
Merge branch 'feat/script-utils' into feat/bcs-structs
Foivos Jun 18, 2024
46fc8ea
Merge branch 'feat/bcs-structs' into feat/ts
Foivos Jun 18, 2024
8aeee89
add run.sh back
Foivos Jun 18, 2024
4b1dd9c
add coverage.sh back
Foivos Jun 18, 2024
ad10697
get eslint to work
Foivos Jun 18, 2024
4e62c8f
prettier
Foivos Jun 18, 2024
80c6a6c
allow execution of scripts
Foivos Jun 19, 2024
8ab9ed0
stash
Foivos Jun 19, 2024
1cd9f11
stash
Foivos Jun 19, 2024
fb549fa
added deployment test
Foivos Jun 19, 2024
4886636
fix package scripts
Foivos Jun 19, 2024
5774306
prettier and include mocha
Foivos Jun 19, 2024
d0a4879
remove .env dependancy
Foivos Jun 19, 2024
b143ef4
added a test to rotate signers
Foivos Jun 20, 2024
f71d272
Add a revert util and test
Foivos Jun 21, 2024
df94e7e
prettier
Foivos Jun 21, 2024
afc4c9c
run imp i to fix tests
Foivos Jun 21, 2024
8c5f516
added flow limits and scaling all incoming decimals down to 9
Foivos Jun 26, 2024
5b1e687
added proper token handling and helper function for minting/burning a…
Foivos Jun 26, 2024
4e4d73a
Merge remote-tracking branch 'origin/feat/testing' into feat/its-scal…
Foivos Jun 26, 2024
c31fda9
dinished adding all the features for flow limits and decimals convers…
Foivos Jul 1, 2024
b237b8f
add a test file
Foivos Jul 2, 2024
fb4bb73
update with a event detecting utils
Foivos Jul 3, 2024
c3d65b4
remove scaling to split into two PRs
Foivos Jul 4, 2024
7d0ae47
Merge branch 'feat/testing' into feat/flow-limits
Foivos Jul 4, 2024
4d335fb
resolve all conflicts from merge
Foivos Jul 4, 2024
c339779
made lint happy
Foivos Jul 4, 2024
2fbd038
seperate tests to move and js
Foivos Jul 4, 2024
9d810fe
try to run sui localnet again
Foivos Jul 4, 2024
56623c4
add sui-test-validator to path
Foivos Jul 4, 2024
9ce9418
ls
Foivos Jul 4, 2024
3952378
seperate tests properly
Foivos Jul 4, 2024
ac8e05c
ls
Foivos Jul 4, 2024
cc0037a
ls again
Foivos Jul 4, 2024
2c8225d
skip cache
Foivos Jul 4, 2024
ae2f1b6
use correct sui-test-validator
Foivos Jul 4, 2024
c0c7314
try to run in parralel
Foivos Jul 4, 2024
41e674f
try waiting for localnet
Foivos Jul 4, 2024
2c9d173
Merge remote-tracking branch 'origin/main' into feat/its-scale-coins
Foivos Jul 30, 2024
f7c04a0
fixed move tests
Foivos Jul 30, 2024
3256b02
fix lint
Foivos Jul 30, 2024
88b32a9
fix js tests
Foivos Jul 30, 2024
483a0cf
fix install
Foivos Jul 30, 2024
6097926
prettier
Foivos Jul 30, 2024
b5c9e33
Merge branch 'feat/its-scale-coins' into feat/flow-limits
Foivos Jul 30, 2024
3586feb
fix move tests
Foivos Jul 30, 2024
30ee624
clean move.toml
Foivos Jul 31, 2024
66cbc69
Merge remote-tracking branch 'origin/main' into feat/flow-limits
Foivos Jul 31, 2024
b4ab1d9
fix move tests
Foivos Jul 31, 2024
0693809
add support for HUB routing
Foivos Jul 31, 2024
2626a5b
Merge remote-tracking branch 'origin/main' into feat/its-hub
Foivos Jul 31, 2024
8d7be3f
address some comments
Foivos Aug 1, 2024
ae88251
fix some logic
Foivos Aug 1, 2024
fee6aeb
update logic to match evm
Foivos Aug 26, 2024
22e366a
Merge remote-tracking branch 'origin/main' into feat/its-hub
Foivos Sep 2, 2024
9311e37
some formatting
Foivos Sep 3, 2024
f688992
Update move/its/sources/service.move
Foivos Sep 3, 2024
84cb49b
some formatting
Foivos Sep 3, 2024
6843a8d
fix logic a bit
Foivos Sep 3, 2024
a9439fd
some comments addressed
Foivos Sep 3, 2024
dbeaf58
Merge remote-tracking branch 'origin/main' into feat/its-hub
Foivos Sep 3, 2024
a18c511
addressed comments again
Foivos Sep 3, 2024
2ede7a0
fix bug
Foivos Sep 3, 2024
c741d48
formatting
Foivos Sep 3, 2024
e58fb59
fix code again
Foivos Sep 3, 2024
56f6a7a
fix move tests
Foivos Sep 3, 2024
23c44b1
fix code
Foivos Sep 3, 2024
b7a9f7f
Merge remote-tracking branch 'origin/main' into feat/its-hub
Foivos Sep 3, 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
13 changes: 11 additions & 2 deletions move/its/sources/discovery.move
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module its::discovery {
const MESSAGE_TYPE_INTERCHAIN_TRANSFER: u256 = 0;
const MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN: u256 = 1;
//const MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER: u256 = 2;
//const MESSAGE_TYPE_SEND_TO_HUB: u256 = 3;
const MESSAGE_TYPE_RECEIVE_FROM_HUB: u256 = 4;

public fun get_interchain_transfer_info(payload: vector<u8>): (TokenId, address, u64, vector<u8>) {
let mut reader = abi::new_reader(payload);
Expand Down Expand Up @@ -66,9 +68,16 @@ module its::discovery {
));
}

public fun get_call_info(self: &ITS, payload: vector<u8>): Transaction {
public fun get_call_info(self: &ITS, mut payload: vector<u8>): Transaction {
let mut reader = abi::new_reader(payload);
let message_type = reader.read_u256();
let mut message_type = reader.read_u256();

if (message_type == MESSAGE_TYPE_RECEIVE_FROM_HUB) {
reader.skip_slot();
payload = reader.read_bytes();
reader = abi::new_reader(payload);
message_type = reader.read_u256();
};

if (message_type == MESSAGE_TYPE_INTERCHAIN_TRANSFER) {
get_interchain_transfer_tx(self, &mut reader)
Foivos marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
47 changes: 43 additions & 4 deletions move/its/sources/service.move
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ module its::service {
const MESSAGE_TYPE_INTERCHAIN_TRANSFER: u256 = 0;
const MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN: u256 = 1;
//const MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER: u256 = 2;
const MESSAGE_TYPE_SEND_TO_HUB: u256 = 3;
const MESSAGE_TYPE_RECEIVE_FROM_HUB: u256 = 4;

/**
* @dev Chain name for Axelar. This is used for routing ITS calls via ITS hub on Axelar.
*/
Foivos marked this conversation as resolved.
Show resolved Hide resolved
const ITS_HUB_CHAIN_NAME: vector<u8> = b"Axelarnet";

/**
* @dev Identifier to be used as destination address for chains that route to hub. For Sui this will probably be every supported chain.
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
*/
const ITS_HUB_ROUTING_IDENTIFIER: vector<u8> = b"hub";

// address::to_u256(address::from_bytes(keccak256(b"sui-set-trusted-addresses")));
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
const MESSAGE_TYPE_SET_TRUSTED_ADDRESSES: u256 = 0x2af37a0d5d48850a855b1aaaf57f726c107eb99b40eabf4cc1ba30410cfa2f68;
Expand All @@ -43,6 +55,8 @@ module its::service {
const ENonZeroTotalSupply: u64 = 7;
const EUnregisteredCoinHasUrl: u64 = 8;
const EMalformedTrustedAddresses: u64 = 9;
const ESenderNotHub: u64 = 10;
const EUntrustedChain: u64 = 11;

public struct CoinRegistered<phantom T> has copy, drop {
token_id: TokenId,
Expand Down Expand Up @@ -273,20 +287,45 @@ module its::service {
/// Decode an approved call and check that the source chain is trusted.
fun decode_approved_message(self: &mut ITS, approved_message: ApprovedMessage): (String, vector<u8>) {
let (
source_chain,
mut source_chain,
_,
source_address,
payload
mut payload
) = self.channel_mut().consume_approved_message(approved_message);

assert!(self.is_trusted_address(source_chain, source_address), EUntrustedAddress);

let mut reader = abi::new_reader(payload);
if (reader.read_u256() == MESSAGE_TYPE_RECEIVE_FROM_HUB) {
assert!(source_chain.into_bytes() == ITS_HUB_CHAIN_NAME, ESenderNotHub);
source_chain = ascii::string(reader.read_bytes());
Foivos marked this conversation as resolved.
Show resolved Hide resolved
Foivos marked this conversation as resolved.
Show resolved Hide resolved
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
payload = reader.read_bytes();
};

(source_chain, payload)
}

/// Send a payload to a destination chain. The destination chain needs to have a trusted address.
fun send_payload(self: &mut ITS, destination_chain: String, payload: vector<u8>) {
let destination_address = self.get_trusted_address(destination_chain);
fun send_payload(self: &mut ITS, mut destination_chain: String, mut payload: vector<u8>) {
let mut destination_address = self.get_trusted_address(destination_chain);

// Prevent sending directly to the ITS Hub chain. This is not supported yet, so fail early to prevent the user from having their funds stuck.
assert!(destination_chain.into_bytes() != ITS_HUB_CHAIN_NAME, EUntrustedChain);

// Check whether the ITS call should be routed via ITS hub for this destination chain
if(destination_address.into_bytes() == ITS_HUB_ROUTING_IDENTIFIER) {
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
let mut writter = abi::new_writer(3);
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
writter.write_u256(MESSAGE_TYPE_SEND_TO_HUB);
writter.write_bytes(destination_chain.into_bytes());
Foivos marked this conversation as resolved.
Show resolved Hide resolved
writter.write_bytes(payload);
payload = writter.into_bytes();
destination_chain = ascii::string(ITS_HUB_CHAIN_NAME);
destination_address = self.get_trusted_address(destination_chain);
};

// Check whether no trusted address was set for the destination chain
assert!(destination_address.length() > 0, EUntrustedChain);
milapsheth marked this conversation as resolved.
Show resolved Hide resolved

gateway::call_contract(self.channel_mut(), destination_chain, destination_address, payload);
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading