Skip to content

Snowbridge V2: A base branch for Snowbridge V2 (for diff only) #1478

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 9 additions & 7 deletions contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,18 @@ contract Gateway is IGatewayBase, IGatewayV1, IGatewayV2, IInitializable, IUpgra
revert IGatewayBase.InvalidNonce();
}

bytes32 leafHash = keccak256(abi.encode(message));

$.inboundNonce.set(message.nonce);

// Produce the commitment (message root) by applying the leaf proof to the message leaf
bytes32 commitment = MerkleProof.processProof(leafProof, leafHash);
if (msg.sender != address(this)) {
bytes32 leafHash = keccak256(abi.encode(message));

// Verify that the commitment is included in a parachain header finalized by BEEFY.
if (!_verifyCommitment(commitment, headerProof, true)) {
revert IGatewayBase.InvalidProof();
// Produce the commitment (message root) by applying the leaf proof to the message leaf
bytes32 commitment = MerkleProof.processProof(leafProof, leafHash);

// Verify that the commitment is included in a parachain header finalized by BEEFY.
if (!_verifyCommitment(commitment, headerProof, true)) {
revert IGatewayBase.InvalidProof();
}
}

// Dispatch the message payload. The boolean returned indicates whether all commands succeeded.
Expand Down
84 changes: 33 additions & 51 deletions web/packages/api/src/assets_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,12 @@ export async function getLocationBalance(
}
case "muse":
case "mythos": {
return await getMythosLocationBalance(
location, provider, specName, account
)
return await getMythosLocationBalance(location, provider, specName, account)
}
default:
throw Error(`Cannot get balance for spec ${specName}. Location = ${JSON.stringify(location)}`)
throw Error(
`Cannot get balance for spec ${specName}. Location = ${JSON.stringify(location)}`
)
}
}

Expand Down Expand Up @@ -982,21 +982,25 @@ async function indexParachain(
isFunction(provider.call.xcmPaymentApi?.queryWeightToAssetFee)

// test getting balances
let hasDotBalance = true;
let hasDotBalance = true
try {
await getDotBalance(
provider,
info.specName,
info.accountType === "AccountId32" ? "0x0000000000000000000000000000000000000000000000000000000000000000" : "0x0000000000000000000000000000000000000000"
info.accountType === "AccountId32"
? "0x0000000000000000000000000000000000000000000000000000000000000000"
: "0x0000000000000000000000000000000000000000"
)
} catch(err) {
} catch (err) {
console.warn(`Spec ${info.specName} does not support dot ${err}`)
hasDotBalance = false
}

await getNativeBalance(
provider,
info.accountType === "AccountId32" ? "0x0000000000000000000000000000000000000000000000000000000000000000" : "0x0000000000000000000000000000000000000000"
info.accountType === "AccountId32"
? "0x0000000000000000000000000000000000000000000000000000000000000000"
: "0x0000000000000000000000000000000000000000"
)

let estimatedExecutionFeeDOT = 0n
Expand Down Expand Up @@ -1287,35 +1291,6 @@ function addOverrides(envName: string, result: RegistryOptions) {
}
case "local_e2e": {
result.assetOverrides = {
"1000": [
{
token: "0xDe45448Ca2d57797c0BEC0ee15A1E42334744219".toLowerCase(),
name: "wnd",
minimumBalance: 1n,
symbol: "wnd",
decimals: 18,
isSufficient: true,
location: DOT_LOCATION,
},
{
token: "0xD8597EB7eF761E3315623EdFEe9DEfcBACd72e8b".toLowerCase(),
name: "pal-2",
minimumBalance: 1n,
symbol: "pal-2",
decimals: 18,
isSufficient: true,
location: {
parents: 1,
interior: {
x3: [
{ parachain: 2000 },
{ palletInstance: 50 },
{ generalIndex: 2 },
],
},
},
},
],
"2000": [
{
token: "0xD8597EB7eF761E3315623EdFEe9DEfcBACd72e8b".toLowerCase(),
Expand Down Expand Up @@ -1379,10 +1354,8 @@ function defaultPathFilter(envName: string): (_: Path) => boolean {
// Disallow MUSE to any location but 3369
if (
path.asset === MUSE_TOKEN_ID &&
(
(path.destination !== 3369 && path.type === "ethereum") ||
(path.source !== 3369 && path.type === "substrate")
)
((path.destination !== 3369 && path.type === "ethereum") ||
(path.source !== 3369 && path.type === "substrate"))
) {
return false
}
Expand All @@ -1397,10 +1370,8 @@ function defaultPathFilter(envName: string): (_: Path) => boolean {
// Disallow MYTH to any location but 3369
if (
path.asset === MYTHOS_TOKEN_ID &&
(
(path.destination !== 3369 && path.type === "ethereum") ||
(path.source !== 3369 && path.type === "substrate")
)
((path.destination !== 3369 && path.type === "ethereum") ||
(path.source !== 3369 && path.type === "substrate"))
) {
return false
}
Expand Down Expand Up @@ -1485,7 +1456,9 @@ async function indexPNAs(
pnas.push(assetInfo)
}
let assetOverrides: any = {}
assetOverrides[assetHubParaId.toString()] = pnas
if (pnas.length) {
assetOverrides[assetHubParaId.toString()] = pnas
}
return assetOverrides
}

Expand Down Expand Up @@ -1558,7 +1531,8 @@ function bridgeablePNAsOnAH(environment: string, location: any, assetHubParaId:
}
// Add assets for Westend
switch (environment) {
case "westend_sepolia": {
case "westend_sepolia":
case "local_e2e":
if (
location.interior.x1 &&
location.interior.x1[0]?.globalConsensus?.byGenesis === WESTEND_GENESIS
Expand All @@ -1580,11 +1554,15 @@ function bridgeablePNAsOnAH(environment: string, location: any, assetHubParaId:
},
}
}
}
}
}

export async function getAssetHubConversationPalletSwap(assetHub: ApiPromise, asset1: any, asset2: any, exactAsset2Balance: bigint) {
export async function getAssetHubConversationPalletSwap(
assetHub: ApiPromise,
asset1: any,
asset2: any,
exactAsset2Balance: bigint
) {
const result = await assetHub.call.assetConversionApi.quotePriceTokensForExactTokens(
asset1,
asset2,
Expand All @@ -1593,7 +1571,11 @@ export async function getAssetHubConversationPalletSwap(assetHub: ApiPromise, as
)
const asset1Balance = result.toPrimitive() as any
if (asset1Balance == null) {
throw Error(`No pool set up in asset conversion pallet for '${JSON.stringify(asset1)}' and '${JSON.stringify(asset2)}'.`)
throw Error(
`No pool set up in asset conversion pallet for '${JSON.stringify(
asset1
)}' and '${JSON.stringify(asset2)}'.`
)
}
return BigInt(asset1Balance)
return BigInt(asset1Balance)
}
Loading
Loading