Skip to content

Commit a59a348

Browse files
lrazovicJuaniRios
authored andcommitted
feat: convert key to hex
1 parent f0854d4 commit a59a348

File tree

11 files changed

+165
-93
lines changed

11 files changed

+165
-93
lines changed
-57 Bytes
Binary file not shown.

integration-tests/chopsticks/overrides/polimec.ts

+82-38
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ const dot_location = {
2323
},
2424
};
2525

26+
const weth_location = {
27+
parents: 2,
28+
interior: {
29+
x2: [
30+
{
31+
globalConsensus: {
32+
ethereum: {
33+
chainId: 1n
34+
}
35+
}
36+
},
37+
{
38+
accountKey20: {
39+
key: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
40+
}
41+
}
42+
]
43+
}
44+
}
45+
2646
export const polimec_storage = {
2747
System: {
2848
Account: [
@@ -57,52 +77,75 @@ export const polimec_storage = {
5777
balance: INITIAL_BALANCES.DOT,
5878
},
5979
],
60-
],
61-
Asset: [
62-
[
63-
[usdc_location],
64-
{
65-
owner: Accounts.ALICE,
66-
issuer: Accounts.ALICE,
67-
admin: Accounts.ALICE,
68-
freezer: Accounts.ALICE,
69-
supply: INITIAL_BALANCES.USDC,
70-
deposit: 0n,
71-
min_balance: 70000n,
72-
is_sufficient: true,
73-
accounts: 1,
74-
sufficients: 1,
75-
approvals: 0,
76-
status: 'Live',
77-
},
78-
],
7980
[
80-
[usdt_location],
81+
[weth_location, Accounts.BOB],
8182
{
82-
owner: Accounts.ALICE,
83-
issuer: Accounts.ALICE,
84-
admin: Accounts.ALICE,
85-
freezer: Accounts.ALICE,
86-
supply: INITIAL_BALANCES.USDT,
87-
deposit: 0n,
88-
min_balance: 70000n,
89-
is_sufficient: true,
90-
accounts: 1,
91-
sufficients: 1,
92-
approvals: 0,
93-
status: 'Live',
83+
balance: INITIAL_BALANCES.WETH,
9484
},
9585
],
86+
],
87+
Asset: [
88+
// [
89+
// [usdc_location],
90+
// {
91+
// owner: Accounts.ALICE,
92+
// issuer: Accounts.ALICE,
93+
// admin: Accounts.ALICE,
94+
// freezer: Accounts.ALICE,
95+
// supply: INITIAL_BALANCES.USDC,
96+
// deposit: 0n,
97+
// min_balance: 70000n,
98+
// is_sufficient: true,
99+
// accounts: 1,
100+
// sufficients: 1,
101+
// approvals: 0,
102+
// status: 'Live',
103+
// },
104+
// ],
105+
// [
106+
// [usdt_location],
107+
// {
108+
// owner: Accounts.ALICE,
109+
// issuer: Accounts.ALICE,
110+
// admin: Accounts.ALICE,
111+
// freezer: Accounts.ALICE,
112+
// supply: INITIAL_BALANCES.USDT,
113+
// deposit: 0n,
114+
// min_balance: 70000n,
115+
// is_sufficient: true,
116+
// accounts: 1,
117+
// sufficients: 1,
118+
// approvals: 0,
119+
// status: 'Live',
120+
// },
121+
// ],
122+
// [
123+
// [dot_location],
124+
// {
125+
// owner: Accounts.ALICE,
126+
// issuer: Accounts.ALICE,
127+
// admin: Accounts.ALICE,
128+
// freezer: Accounts.ALICE,
129+
// supply: INITIAL_BALANCES.DOT,
130+
// deposit: 0n,
131+
// min_balance: 100000000n,
132+
// is_sufficient: true,
133+
// accounts: 1,
134+
// sufficients: 1,
135+
// approvals: 0,
136+
// status: 'Live',
137+
// },
138+
// ],
96139
[
97-
[dot_location],
140+
[weth_location],
98141
{
99142
owner: Accounts.ALICE,
100143
issuer: Accounts.ALICE,
101144
admin: Accounts.ALICE,
102145
freezer: Accounts.ALICE,
103-
supply: INITIAL_BALANCES.DOT,
146+
supply: INITIAL_BALANCES.WETH,
104147
deposit: 0n,
105-
min_balance: 100000000n,
148+
min_balance: 1000000n,
106149
is_sufficient: true,
107150
accounts: 1,
108151
sufficients: 1,
@@ -112,9 +155,10 @@ export const polimec_storage = {
112155
],
113156
],
114157
Metadata: [
115-
[[usdc_location], { symbol: 'USDC', name: 'USDC', decimals: 6, isFrozen: false }],
116-
[[usdt_location], { symbol: 'USDT', name: 'USDC', decimals: 6, isFrozen: false }],
117-
[[dot_location], { symbol: 'DOT', name: 'DOT', decimals: 10, isFrozen: false }],
158+
// [[usdc_location], { symbol: 'USDC', name: 'USDC', decimals: 6, isFrozen: false }],
159+
// [[usdt_location], { symbol: 'USDT', name: 'USDC', decimals: 6, isFrozen: false }],
160+
// [[dot_location], { symbol: 'DOT', name: 'DOT', decimals: 10, isFrozen: false }],
161+
[[weth_location], { symbol: 'WETH', name: 'WETH', decimals: 18, isFrozen: false }],
118162
],
119163
},
120164
} as const;

integration-tests/chopsticks/overrides/polkadot-hub.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export const polkadot_hub_storage = {
5454
},
5555
ForeignAssets: {
5656
Account: [
57-
[[weth_location, Accounts.ALICE], { balance: 10000000000000 }]
57+
[[weth_location, Accounts.ALICE], { balance: INITIAL_BALANCES.WETH }]
5858
],
5959
Asset: [
60-
[[weth_location], { supply: 10000000000000 }]
60+
[[weth_location], { supply: INITIAL_BALANCES.WETH }]
6161
]
6262
}
6363
} as const;

integration-tests/chopsticks/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
"@types/bun": "latest"
1414
},
1515
"peerDependencies": {
16-
"typescript": "^5.0.0"
16+
"typescript": "^5.7.3"
1717
},
1818
"dependencies": {
1919
"@polkadot-api/descriptors": "file:.papi/descriptors",
20-
"@polkadot/keyring": "13.2.3",
21-
"lodash": "^4.17.21",
22-
"polkadot-api": "^1.7.7"
20+
"polkadot-api": "^1.8.2"
2321
}
2422
}

integration-tests/chopsticks/src/managers/PolimecManager.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isEqual } from 'lodash';
44
import { createClient } from 'polkadot-api';
55
import { getWsProvider } from 'polkadot-api/ws-provider/web';
66
import { BaseChainManager } from './BaseManager';
7+
import { normalizeForComparison } from '@/utils.ts';
78

89
export class PolimecManager extends BaseChainManager {
910
connect() {
@@ -60,7 +61,7 @@ export class PolimecManager extends BaseChainManager {
6061
if (account_balances_result.success === true && account_balances_result.value.type === 'V4') {
6162
const assets = account_balances_result.value.value;
6263
for (const asset of assets) {
63-
if (Bun.deepEquals(asset.id, asset_location)) {
64+
if (Bun.deepEquals(normalizeForComparison(asset.id), normalizeForComparison(asset_location))) {
6465
console.log('Found asset. Balance is: ', asset.fun.value);
6566
console.dir(asset, { depth: null, colors: true });
6667
console.log('\n\n');

integration-tests/chopsticks/src/managers/PolkadotHubManager.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { type Accounts, Asset, AssetLocation, AssetSourceRelation, Chains } from '@/types';
22
import { pah } from '@polkadot-api/descriptors';
3-
import { isEqual } from 'lodash';
43
import { createClient } from 'polkadot-api';
54
import { getWsProvider } from 'polkadot-api/ws-provider/web';
65
import { BaseChainManager } from './BaseManager';
6+
import { normalizeForComparison } from '@/utils.ts';
7+
8+
79

810
export class PolkadotHubManager extends BaseChainManager {
911
connect() {
@@ -44,38 +46,39 @@ export class PolkadotHubManager extends BaseChainManager {
4446
return AssetSourceRelation.Self;
4547
}
4648
}
49+
4750
async getAssetBalanceOf(account: Accounts, asset: Asset): Promise<bigint> {
4851
const api = this.getApi(Chains.PolkadotHub);
4952
const asset_source_relation = this.getAssetSourceRelation(asset);
5053
const asset_location = AssetLocation(asset, asset_source_relation).value;
5154
const account_balances_result = await api.apis.FungiblesApi.query_account_balances(account);
5255
console.log('Requested asset location in PolkadotHubManager');
5356
console.dir(asset_location, { depth: null, colors: true });
54-
let maybe_account_key_20 = asset_location.interior.value[1].value?.key?.asHex();
55-
console.log('Maybe Account key 20', maybe_account_key_20);
5657

5758
console.log('\n\n');
5859
if (account_balances_result.success === true && account_balances_result.value.type === 'V4') {
5960
const assets = account_balances_result.value.value;
6061
for (const asset of assets) {
61-
if (Bun.deepEquals(asset.id, asset_location)) {
62+
if (
63+
Bun.deepEquals(normalizeForComparison(asset.id), normalizeForComparison(asset_location))
64+
) {
6265
console.log('Found asset. Balance is: ', asset.fun.value);
63-
console.dir(asset, { depth: null, colors: true });
66+
console.dir(normalizeForComparison(asset), { depth: null, colors: true });
6467
console.log('\n\n');
6568
return asset.fun.value;
6669
}
6770
console.log('Not it chief: \n');
68-
console.dir(asset, { depth: null, colors: true });
71+
console.dir(normalizeForComparison(asset.id), { depth: null, colors: true });
72+
6973
console.log('\n\n');
7074

71-
let maybe_account_key_20 = asset.id.interior.value?.[1].value?.key?.asHex();
72-
console.log('Maybe Account key 20', maybe_account_key_20);
7375
}
7476
}
7577
console.log('Asset not found');
7678
console.log('\n\n');
7779
return 0n;
7880
}
81+
7982
async getSwapCredit() {
8083
const api = this.getApi(Chains.PolkadotHub);
8184
const events = await api.event.AssetConversion.SwapCreditExecuted.pull();
@@ -85,7 +88,7 @@ export class PolkadotHubManager extends BaseChainManager {
8588
async getXcmFee() {
8689
const api = this.getApi(Chains.PolkadotHub);
8790
const events = await api.event.PolkadotXcm.FeesPaid.pull();
88-
console.log("Fees paid event")
91+
console.log('Fees paid event');
8992
console.dir(events, { depth: null, colors: true });
9093
return (events[0]?.payload.fees[0].fun.value as bigint) || 0n;
9194
}

integration-tests/chopsticks/src/tests/hub.test.ts

+36-36
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,50 @@ describe('Polkadot Hub -> Polimec Transfer Tests', () => {
1717
destManager.connect();
1818
});
1919
afterAll(async () => await chainSetup.cleanup());
20-
//
21-
// test(
22-
// 'Send DOT to Polimec',
23-
// () =>
24-
// transferTest.testTransfer({
25-
// account: Accounts.ALICE,
26-
// assets: [[Asset.DOT, TRANSFER_AMOUNTS.NATIVE, AssetSourceRelation.Parent]],
27-
// }),
28-
// { timeout: 25000 },
29-
// );
30-
//
31-
// test(
32-
// 'Send USDT to Polimec',
33-
// () =>
34-
// transferTest.testTransfer({
35-
// account: Accounts.ALICE,
36-
// assets: [[Asset.USDT, TRANSFER_AMOUNTS.TOKENS, AssetSourceRelation.Self]],
37-
// }),
38-
// { timeout: 25000 },
39-
// );
40-
//
41-
// test(
42-
// 'Send USDC to Polimec',
43-
// () =>
44-
// transferTest.testTransfer({
45-
// account: Accounts.ALICE,
46-
// assets: [[Asset.USDC, TRANSFER_AMOUNTS.TOKENS, AssetSourceRelation.Self]],
47-
// }),
48-
// { timeout: 25000 },
49-
// );
5020

5121
test(
52-
'Send WETH to Polimec',
22+
'Send DOT to Polimec',
23+
() =>
24+
transferTest.testTransfer({
25+
account: Accounts.ALICE,
26+
assets: [[Asset.DOT, TRANSFER_AMOUNTS.NATIVE, AssetSourceRelation.Parent]],
27+
}),
28+
{ timeout: 25000 },
29+
);
30+
31+
test(
32+
'Send USDT to Polimec',
5333
() =>
5434
transferTest.testTransfer({
5535
account: Accounts.ALICE,
56-
assets: [
57-
[Asset.USDT, TRANSFER_AMOUNTS.TOKENS, AssetSourceRelation.Self],
58-
[Asset.WETH, TRANSFER_AMOUNTS.BRIDGED, AssetSourceRelation.Self],
59-
],
36+
assets: [[Asset.USDT, TRANSFER_AMOUNTS.TOKENS, AssetSourceRelation.Self]],
6037
}),
61-
{ timeout: 10000000 },
38+
{ timeout: 25000 },
6239
);
6340

41+
test(
42+
'Send USDC to Polimec',
43+
() =>
44+
transferTest.testTransfer({
45+
account: Accounts.ALICE,
46+
assets: [[Asset.USDC, TRANSFER_AMOUNTS.TOKENS, AssetSourceRelation.Self]],
47+
}),
48+
{ timeout: 25000 },
49+
);
50+
51+
// test(
52+
// 'Send WETH to Polimec',
53+
// () =>
54+
// transferTest.testTransfer({
55+
// account: Accounts.ALICE,
56+
// assets: [
57+
// // [Asset.USDT, TRANSFER_AMOUNTS.TOKENS, AssetSourceRelation.Self],
58+
// [Asset.WETH, TRANSFER_AMOUNTS.BRIDGED, AssetSourceRelation.Self],
59+
// ],
60+
// }),
61+
// { timeout: 25000 },
62+
// );
63+
6464
// test('sandbox', async () => {
6565
// console.log("hello");
6666
// const weth_1 = {

integration-tests/chopsticks/src/types.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ export function AssetLocation(
162162

163163
case Asset.WETH: {
164164
const contract_hex = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
165-
const byteArray = hexToU8a(contract_hex);
166-
return EthereumAssetLocation(new FixedSizeBinary(byteArray));
165+
return EthereumAssetLocation(FixedSizeBinary.fromHex(contract_hex));
167166
}
168167
}
169168
}

integration-tests/chopsticks/src/utils.ts

+24
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,27 @@ export function unwrap<T>(value: T | undefined, errorMessage = 'Value is undefin
114114
}
115115
return value;
116116
}
117+
118+
export function normalizeForComparison(obj: any): any {
119+
if (obj === null || obj === undefined) {
120+
return obj;
121+
}
122+
123+
if (obj instanceof Object && 'asHex' in obj) {
124+
return obj.asHex();
125+
}
126+
127+
if (typeof obj === 'object') {
128+
if (Array.isArray(obj)) {
129+
return obj.map(normalizeForComparison);
130+
}
131+
132+
const normalized: any = {};
133+
for (const [key, value] of Object.entries(obj)) {
134+
normalized[key] = normalizeForComparison(value);
135+
}
136+
return normalized;
137+
}
138+
139+
return obj;
140+
}

pallets/funding/src/runtime_api.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::traits::BondingRequirementCalculation;
21
#[allow(clippy::wildcard_imports)]
32
use crate::{traits::BondingRequirementCalculation, *};
43
use alloc::{collections::BTreeMap, string::String};

0 commit comments

Comments
 (0)