-
Notifications
You must be signed in to change notification settings - Fork 150
Transact from eth to sub #1141
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
Transact from eth to sub #1141
Changes from 30 commits
55cc688
07395ce
d41bd08
16e7cbe
a01aaab
b660ea8
89feaf3
a94183a
7a110d3
b57f0c1
3ad5b7d
e93c725
65714ef
4719a42
a78b1f9
c192361
acf2362
207460d
f8f0f57
00abc13
5084432
d7cc7d8
2f3560c
e99ce53
2e4140c
dd3378e
3d91da4
ac7e1f5
72f6d3e
68a567f
923187e
3dd1adc
f07507f
70413d8
a364298
bdf4c71
748eea4
e27c0eb
e5c1a70
53791d2
61d5ea5
dfa331d
b935ca8
2847751
bfdff26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,9 @@ import { | |
| Command, | ||
| MultiAddress, | ||
| Ticket, | ||
| Costs | ||
| Costs, | ||
| OriginKind, | ||
| Weight | ||
| } from "./Types.sol"; | ||
| import {IGateway} from "./interfaces/IGateway.sol"; | ||
| import {IInitializable} from "./interfaces/IInitializable.sol"; | ||
|
|
@@ -27,6 +29,7 @@ import {SafeNativeTransfer} from "./utils/SafeTransfer.sol"; | |
| import {Call} from "./utils/Call.sol"; | ||
| import {Math} from "./utils/Math.sol"; | ||
| import {ScaleCodec} from "./utils/ScaleCodec.sol"; | ||
| import {SubstrateTypes} from "./SubstrateTypes.sol"; | ||
|
|
||
| import { | ||
| UpgradeParams, | ||
|
|
@@ -623,4 +626,30 @@ contract Gateway is IGateway, IInitializable { | |
| assets.assetHubCreateAssetFee = config.assetHubCreateAssetFee; | ||
| assets.assetHubReserveTransferFee = config.assetHubReserveTransferFee; | ||
| } | ||
|
|
||
| // Calculate cost for transact | ||
| function _calculateTransactCost(uint128 destinationFee) internal pure returns (Costs memory costs) { | ||
| return Costs({native: 0, foreign: destinationFee}); | ||
| } | ||
|
|
||
| /// @inheritdoc IGateway | ||
| function sendCall( | ||
| ParaID destinationChain, | ||
| OriginKind originKind, | ||
| uint128 destinationFee, | ||
| Weight calldata weightAtMost, | ||
| bytes calldata call | ||
alistair-singh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) external payable { | ||
| bytes memory payload = | ||
| SubstrateTypes.Transact(msg.sender, originKind.encode(), destinationFee, weightAtMost, call); | ||
| Costs memory costs = _calculateTransactCost(destinationFee); | ||
| Ticket memory ticket = Ticket({dest: destinationChain, costs: costs, payload: payload}); | ||
| _submitOutbound(ticket); | ||
| } | ||
|
|
||
| /// @inheritdoc IGateway | ||
| function quoteSendCallFee(uint128 destinationFee) external view returns (uint256) { | ||
|
||
| Costs memory costs = _calculateTransactCost(destinationFee); | ||
|
||
| return _calculateFee(costs); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,4 +47,16 @@ contract ScaleCodecTest is Test { | |
| vm.expectRevert(ScaleCodec.UnsupportedCompactEncoding.selector); | ||
| ScaleCodec.checkedEncodeCompactU32(uint256(type(uint32).max) + 1); | ||
| } | ||
|
|
||
| function testEncodeCompactU64() public { | ||
| assertEq(ScaleCodec.encodeCompactU64(0), hex"00"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
| assertEq(ScaleCodec.encodeCompactU64(63), hex"fc"); | ||
| assertEq(ScaleCodec.encodeCompactU64(64), hex"0101"); | ||
| assertEq(ScaleCodec.encodeCompactU64(16383), hex"fdff"); | ||
| assertEq(ScaleCodec.encodeCompactU64(16384), hex"02000100"); | ||
| assertEq(ScaleCodec.encodeCompactU64(1073741823), hex"feffffff"); | ||
| assertEq(ScaleCodec.encodeCompactU64(1073741824), hex"0300000040"); | ||
| assertEq(ScaleCodec.encodeCompactU64(type(uint32).max), hex"03ffffffff"); | ||
| assertEq(ScaleCodec.encodeCompactU64(type(uint64).max), hex"13ffffffffffffffff"); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.