Skip to content

Commit

Permalink
failing to decode poolAssets
Browse files Browse the repository at this point in the history
  • Loading branch information
bee344 committed Jan 11, 2024
1 parent ac66157 commit e0ea727
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
21 changes: 17 additions & 4 deletions e2e-tests/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export const balanceTracker = async (
if (!balance) {
for (const assetId of assetIds) {
accountInfo = (await api.query.foreignAssets.account(assetId, address)) as Option<PalletAssetsAssetAccount>;
balances.initial.push([assetId, accountInfo.unwrap().balance.toBn().toNumber()]);
if (accountInfo.valueOf() === null) {
balances.initial.push([assetId, 0]);
} else {
balances.initial.push([assetId, accountInfo.unwrap().balance.toBn().toNumber()]);
}
}
} else {
balances = balance;
Expand All @@ -36,7 +40,12 @@ export const balanceTracker = async (
if (!balance) {
for (const assetId of assetIds) {
accountInfo = await api.query.poolAssets.account(assetId, address);
balances.initial.push([assetId, accountInfo.unwrap().balance.toBn().toNumber()]);
console.log(accountInfo.value.toHuman())

Check failure on line 43 in e2e-tests/balance.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
if (accountInfo.isNone) {
balances.initial.push([assetId, 0]);
} else {
balances.initial.push([assetId, accountInfo.unwrap().balance.toBn().toNumber()]);
}
}
} else {
balances = balance;
Expand All @@ -49,7 +58,11 @@ export const balanceTracker = async (
case '--local':
if (!balance) {
accountInfo = await api.query.system.account(address);
balances.initial.push(['0', Number(accountInfo.data.free)]);
if (accountInfo === null) {
balances.initial.push(['0', 0]);
} else {
balances.initial.push(['0', Number(accountInfo.data.free)]);
}
} else {
balances = balance;
accountInfo = await api.query.system.account(address);
Expand All @@ -60,7 +73,7 @@ export const balanceTracker = async (
if (!balance) {
for (const assetId of assetIds) {
accountInfo = await api.query.assets.account(assetId, address);
if (accountInfo.valueOf() == null) {
if (accountInfo === null) {
balances.initial.push([assetId, 0]);
} else {
balances.initial.push([assetId, accountInfo.unwrap().balance.toBn().toNumber()]);
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export const tests: TestGroups = {
args: [
'1000',
'1000',
'//Alice',
BOB_KAH_ADDR,
'//Bob',
FERDE_KAH_ADDR,
'[0]',
'[30000]',
'{ "format": "payload", "xcmVersion": 3, "transferLiquidToken": true, "paysWithFeeOrigin": { "parents": "0", "interior": { "X2": [{"PalletInstance": "50"}, { "GeneralIndex": "1" }]}}, "sendersAddr": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" }',
Expand Down
34 changes: 19 additions & 15 deletions e2e-tests/tests/liquidPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,33 @@ const createPayFeesTransaction = async (

let localTransferInfo: TxResult<'payload'>;
try {
localTransferInfo = await assetApi.createTransferTransaction(destChainId, destAddr, assetIds, amounts, opts);
const signature = api.registry
.createType('ExtrinsicPayload', localTransferInfo, {
version: 4,
})
.sign(origin).signature as unknown as `0x${string}`;

const extrinsic = api.registry.createType(
'Extrinsic',
{ method: localTransferInfo.method },
{ version: 4 }
);

let sender: string;
if (opts["sendersAddr"] === undefined) {
sender = ''
} else {
sender = opts["sendersAddr"];
}

const signed = extrinsic.addSignature(sender, signature, localTransferInfo as unknown as `0x${string}`).toHex()
localTransferInfo = await assetApi.createTransferTransaction(destChainId, destAddr, assetIds, amounts, opts);
console.log(localTransferInfo.tx)

const payload = api.createType('ExtrinsicPayload', localTransferInfo.tx, {
version: 4,
})

const message = payload.toU8a({ method: true });

const signat = origin.sign(message, { withType: true });

const extrinsic = api.createType(
'Extrinsic',
{ method: localTransferInfo.method },
{ version: 4 }
).addSignature(sender, signat, localTransferInfo.tx);

const tx = extrinsic.toHex()

await api.rpc.author.submitExtrinsic(signed)
await api.rpc.author.submitExtrinsic(tx);

} catch (e) {
console.error(e);
Expand Down
26 changes: 11 additions & 15 deletions src/AssetTransferApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,6 @@ export class AssetTransferApi {

try {
feeAsset = sanitizeKeys(JSON.parse(paysWithFeeOrigin)) as UnionXcmMultiLocation;
console.log(feeAsset)
} catch (err: unknown) {
throw new BaseError(
`paysWithFeeOrigin value must be a valid MultiLocation. Received: ${paysWithFeeOrigin}`,
Expand All @@ -899,23 +898,20 @@ export class AssetTransferApi {

if (this._api.query.assetConversion !== undefined) {
try {
for (const poolPairsData of await this._api.query.assetConversion.pools.entries()) {
const poolStorageKeyData = poolPairsData[0];
console.log('poolAssetDataStr ' + poolStorageKeyData);

for (const poolPairsData of await this._api.query.assetConversion.pools.keys()) {
const poolStorageKeyData = poolPairsData.toHuman();

// remove any commas from multilocation key values e.g. Parachain: 2,125 -> Parachain: 2125
const poolAssetDataStr = JSON.stringify(poolStorageKeyData).replace(/(\d),/g, '$1');
console.log('poolAssetDataStr ' + poolAssetDataStr);
const palletAssetConversionNativeOrAssetIdData = sanitizeKeys(
JSON.parse(poolAssetDataStr),
) as UnionXcmMultiLocation[];


const firstLpToken = palletAssetConversionNativeOrAssetIdData[0];
console.log('first ' + firstLpToken)
const secondLpToken = palletAssetConversionNativeOrAssetIdData[1];
console.log('second ' + secondLpToken)
const firstLpTokenSlice = poolAssetDataStr.slice(2, -2).slice(0, poolAssetDataStr.indexOf('},{"p') -1);
const secondLpTokenSlice = poolAssetDataStr.slice(2, -2).slice(poolAssetDataStr.indexOf('},{"p'));

const firstLpToken = sanitizeKeys(
JSON.parse(firstLpTokenSlice),
) as UnionXcmMultiLocation;
const secondLpToken = sanitizeKeys(
JSON.parse(secondLpTokenSlice),
) as UnionXcmMultiLocation;

if (
JSON.stringify(firstLpToken) == JSON.stringify(feeAsset) ||
Expand Down

0 comments on commit e0ea727

Please sign in to comment.