-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve API for sending tokens (#1009)
- Loading branch information
Showing
10 changed files
with
161 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.22; | ||
|
||
using {isIndex, asIndex, isAddress32, asAddress32, isAddress20, asAddress20} for MultiAddress global; | ||
|
||
/// @dev An address for an on-chain account | ||
struct MultiAddress { | ||
Kind kind; | ||
bytes data; | ||
} | ||
|
||
enum Kind { | ||
Index, | ||
Address32, | ||
Address20 | ||
} | ||
|
||
function isIndex(MultiAddress calldata multiAddress) pure returns (bool) { | ||
return multiAddress.kind == Kind.Index; | ||
} | ||
|
||
function asIndex(MultiAddress calldata multiAddress) pure returns (uint32) { | ||
return abi.decode(multiAddress.data, (uint32)); | ||
} | ||
|
||
function isAddress32(MultiAddress calldata multiAddress) pure returns (bool) { | ||
return multiAddress.kind == Kind.Address32; | ||
} | ||
|
||
function asAddress32(MultiAddress calldata multiAddress) pure returns (bytes32) { | ||
return bytes32(multiAddress.data); | ||
} | ||
|
||
function isAddress20(MultiAddress calldata multiAddress) pure returns (bool) { | ||
return multiAddress.kind == Kind.Address20; | ||
} | ||
|
||
function asAddress20(MultiAddress calldata multiAddress) pure returns (bytes20) { | ||
return bytes20(multiAddress.data); | ||
} | ||
|
||
function multiAddressFromUint32(uint32 id) pure returns (MultiAddress memory) { | ||
return MultiAddress({kind: Kind.Index, data: abi.encode(id)}); | ||
} | ||
|
||
function multiAddressFromBytes32(bytes32 id) pure returns (MultiAddress memory) { | ||
return MultiAddress({kind: Kind.Address32, data: bytes.concat(id)}); | ||
} | ||
|
||
function multiAddressFromBytes20(bytes20 id) pure returns (MultiAddress memory) { | ||
return MultiAddress({kind: Kind.Address20, data: bytes.concat(id)}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.22; | ||
|
||
import { | ||
MultiAddress, multiAddressFromUint32, multiAddressFromBytes32, multiAddressFromBytes20 | ||
} from "./MultiAddress.sol"; | ||
|
||
type ParaID is uint32; | ||
|
||
using {ParaIDEq as ==, ParaIDNe as !=, into} for ParaID global; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.22; | ||
|
||
import {OperatingMode, InboundMessage, ParaID, ChannelID} from "../Types.sol"; | ||
import {OperatingMode, InboundMessage, ParaID, ChannelID, MultiAddress} from "../Types.sol"; | ||
import {Verification} from "../Verification.sol"; | ||
|
||
interface IGateway { | ||
|
@@ -65,7 +65,11 @@ interface IGateway { | |
|
||
/// @dev Emitted once the funds are locked and an outbound message is successfully queued. | ||
event TokenSent( | ||
address indexed token, address indexed sender, ParaID destinationChain, bytes destinationAddress, uint128 amount | ||
address indexed token, | ||
address indexed sender, | ||
ParaID destinationChain, | ||
MultiAddress destinationAddress, | ||
uint128 amount | ||
); | ||
|
||
/// @dev Emitted when a command is sent to register a new wrapped token on AssetHub | ||
|
@@ -79,12 +83,7 @@ interface IGateway { | |
function registerToken(address token) external payable; | ||
|
||
/// @dev Send ERC20 tokens to parachain `destinationChain` and deposit into account `destinationAddress` | ||
function sendToken(address token, ParaID destinationChain, bytes32 destinationAddress, uint128 amount) | ||
external | ||
payable; | ||
|
||
/// @dev Send ERC20 tokens to parachain `destinationChain` and deposit into account `destinationAddress` | ||
function sendToken(address token, ParaID destinationChain, address destinationAddress, uint128 amount) | ||
function sendToken(address token, ParaID destinationChain, MultiAddress calldata destinationAddress, uint128 amount) | ||
external | ||
payable; | ||
} |
Oops, something went wrong.