@pushchain/core 5.1.8 → 5.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -127,7 +127,7 @@ function buildHopDescriptor(ctx, params, route, ueaAddress) {
|
|
|
127
127
|
if ((_b = params.funds) === null || _b === void 0 ? void 0 : _b.amount) {
|
|
128
128
|
const token = params.funds.token;
|
|
129
129
|
if (token) {
|
|
130
|
-
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
130
|
+
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token).address;
|
|
131
131
|
burnAmount = params.funds.amount;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
@@ -233,7 +233,7 @@ function buildHopDescriptor(ctx, params, route, ueaAddress) {
|
|
|
233
233
|
if ((_f = params.funds) === null || _f === void 0 ? void 0 : _f.amount) {
|
|
234
234
|
const token = params.funds.token;
|
|
235
235
|
if (token) {
|
|
236
|
-
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
236
|
+
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token).address;
|
|
237
237
|
burnAmount = params.funds.amount;
|
|
238
238
|
}
|
|
239
239
|
}
|
|
@@ -292,7 +292,7 @@ function buildHopDescriptor(ctx, params, route, ueaAddress) {
|
|
|
292
292
|
amount = params.funds.amount;
|
|
293
293
|
const token = params.funds.token;
|
|
294
294
|
if (token && token.address) {
|
|
295
|
-
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
295
|
+
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token).address;
|
|
296
296
|
}
|
|
297
297
|
else {
|
|
298
298
|
prc20Token = (0, helpers_1.getNativePRC20ForChain)(sourceChain, ctx.pushNetwork);
|
|
@@ -62,7 +62,7 @@ function resolveR2Prc20TokenEvm(params, targetChain, pushNetwork) {
|
|
|
62
62
|
// User explicitly specified funds with token
|
|
63
63
|
const token = params.funds.token;
|
|
64
64
|
if (token) {
|
|
65
|
-
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
65
|
+
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token).address;
|
|
66
66
|
burnAmount = params.funds.amount;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -90,7 +90,7 @@ function resolveR2Prc20TokenSvm(params, targetChain, pushNetwork, hasSvmExecute)
|
|
|
90
90
|
if ((_a = params.funds) === null || _a === void 0 ? void 0 : _a.amount) {
|
|
91
91
|
const token = params.funds.token;
|
|
92
92
|
if (token) {
|
|
93
|
-
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
93
|
+
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token).address;
|
|
94
94
|
burnAmount = params.funds.amount;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -101,7 +101,7 @@ function resolveR2Prc20TokenSvm(params, targetChain, pushNetwork, hasSvmExecute)
|
|
|
101
101
|
else if (hasSvmExecute) {
|
|
102
102
|
const token = params.funds && params.funds.token;
|
|
103
103
|
if (token) {
|
|
104
|
-
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
104
|
+
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token).address;
|
|
105
105
|
}
|
|
106
106
|
else {
|
|
107
107
|
prc20Token = (0, helpers_1.getNativePRC20ForChain)(targetChain, pushNetwork);
|
|
@@ -1269,7 +1269,7 @@ function buildPayloadForRoute(ctx, params, route, nonce) {
|
|
|
1269
1269
|
if ((_a = params.funds) === null || _a === void 0 ? void 0 : _a.amount) {
|
|
1270
1270
|
const token = params.funds.token;
|
|
1271
1271
|
if (token) {
|
|
1272
|
-
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
1272
|
+
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token).address;
|
|
1273
1273
|
burnAmount = params.funds.amount;
|
|
1274
1274
|
}
|
|
1275
1275
|
}
|
|
@@ -1321,7 +1321,7 @@ function buildPayloadForRoute(ctx, params, route, nonce) {
|
|
|
1321
1321
|
if ((_d = params.funds) === null || _d === void 0 ? void 0 : _d.amount) {
|
|
1322
1322
|
const token = params.funds.token;
|
|
1323
1323
|
if (token) {
|
|
1324
|
-
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
1324
|
+
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token).address;
|
|
1325
1325
|
burnAmount = params.funds.amount;
|
|
1326
1326
|
}
|
|
1327
1327
|
}
|
|
@@ -68,7 +68,7 @@ function buildExecuteMulticall({ execute, ueaAddress, logger, }) {
|
|
|
68
68
|
functionName: 'transfer',
|
|
69
69
|
args: [execute.to, (_q = execute.funds) === null || _q === void 0 ? void 0 : _q.amount],
|
|
70
70
|
});
|
|
71
|
-
const pushChainTo = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
71
|
+
const { address: pushChainTo } = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
72
72
|
multicallData.push({
|
|
73
73
|
to: pushChainTo,
|
|
74
74
|
value: BigInt(0),
|
package/src/lib/utils.d.ts
CHANGED
|
@@ -256,21 +256,19 @@ export declare class Utils {
|
|
|
256
256
|
}>;
|
|
257
257
|
};
|
|
258
258
|
/**
|
|
259
|
-
* Convert any supported origin-chain token into its mapped PRC20 token
|
|
259
|
+
* Convert any supported origin-chain token into its mapped PRC20 token on Push Chain.
|
|
260
260
|
*
|
|
261
261
|
* @param token - Either a MoveableToken from `pushChainClient.moveable.token.*`
|
|
262
262
|
* or an object with the origin chain and token address.
|
|
263
|
-
* @returns
|
|
263
|
+
* @returns An object describing the synthetic PRC-20 on Push Chain.
|
|
264
264
|
*
|
|
265
265
|
* @example
|
|
266
266
|
* ```jsx
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* chain: CONSTANTS.CHAIN.ETHEREUM_SEPOLIA
|
|
270
|
-
* address:
|
|
271
|
-
* }
|
|
272
|
-
* );
|
|
273
|
-
* // → `0x...`
|
|
267
|
+
* const { address, chain, symbol, decimals, network } =
|
|
268
|
+
* PushChain.utils.tokens.getPRC20Address({
|
|
269
|
+
* chain: CONSTANTS.CHAIN.ETHEREUM_SEPOLIA,
|
|
270
|
+
* address: '0x...',
|
|
271
|
+
* });
|
|
274
272
|
* ```
|
|
275
273
|
*/
|
|
276
274
|
getPRC20Address(token: MoveableToken | {
|
|
@@ -278,7 +276,13 @@ export declare class Utils {
|
|
|
278
276
|
address: string;
|
|
279
277
|
}, options?: {
|
|
280
278
|
network?: PUSH_NETWORK;
|
|
281
|
-
}):
|
|
279
|
+
}): {
|
|
280
|
+
address: `0x${string}`;
|
|
281
|
+
chain: CHAIN;
|
|
282
|
+
symbol: string;
|
|
283
|
+
decimals: number;
|
|
284
|
+
network: PUSH_NETWORK;
|
|
285
|
+
};
|
|
282
286
|
};
|
|
283
287
|
/**
|
|
284
288
|
* Internal: resolves a CHAIN enum from either a CHAIN value or a PushChain client instance.
|
package/src/lib/utils.js
CHANGED
|
@@ -601,42 +601,55 @@ Utils.tokens = {
|
|
|
601
601
|
return { tokens };
|
|
602
602
|
},
|
|
603
603
|
/**
|
|
604
|
-
* Convert any supported origin-chain token into its mapped PRC20 token
|
|
604
|
+
* Convert any supported origin-chain token into its mapped PRC20 token on Push Chain.
|
|
605
605
|
*
|
|
606
606
|
* @param token - Either a MoveableToken from `pushChainClient.moveable.token.*`
|
|
607
607
|
* or an object with the origin chain and token address.
|
|
608
|
-
* @returns
|
|
608
|
+
* @returns An object describing the synthetic PRC-20 on Push Chain.
|
|
609
609
|
*
|
|
610
610
|
* @example
|
|
611
611
|
* ```jsx
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
* chain: CONSTANTS.CHAIN.ETHEREUM_SEPOLIA
|
|
615
|
-
* address:
|
|
616
|
-
* }
|
|
617
|
-
* );
|
|
618
|
-
* // → `0x...`
|
|
612
|
+
* const { address, chain, symbol, decimals, network } =
|
|
613
|
+
* PushChain.utils.tokens.getPRC20Address({
|
|
614
|
+
* chain: CONSTANTS.CHAIN.ETHEREUM_SEPOLIA,
|
|
615
|
+
* address: '0x...',
|
|
616
|
+
* });
|
|
619
617
|
* ```
|
|
620
618
|
*/
|
|
621
619
|
getPRC20Address(token, options) {
|
|
622
|
-
var _a, _b;
|
|
620
|
+
var _a, _b, _c, _d;
|
|
621
|
+
const network = (_a = options === null || options === void 0 ? void 0 : options.network) !== null && _a !== void 0 ? _a : enums_1.PUSH_NETWORK.TESTNET_DONUT;
|
|
622
|
+
const assertDeployed = (addr, ctx) => {
|
|
623
|
+
if (!addr || addr === '0xTBD') {
|
|
624
|
+
throw new Error(`PRC20 address not available for ${ctx} on network ${network}`);
|
|
625
|
+
}
|
|
626
|
+
return addr;
|
|
627
|
+
};
|
|
623
628
|
// PushChainMoveableToken (pETH, pSOL, pUSDT(BNB), …) carries its PRC-20 address
|
|
624
|
-
//
|
|
625
|
-
const
|
|
626
|
-
if (
|
|
627
|
-
return
|
|
629
|
+
// and origin `sourceChain` directly — no registry lookup needed.
|
|
630
|
+
const pcToken = token;
|
|
631
|
+
if (pcToken.prc20Address) {
|
|
632
|
+
return {
|
|
633
|
+
address: assertDeployed(pcToken.prc20Address, `${(_b = pcToken.symbol) !== null && _b !== void 0 ? _b : 'token'} (${(_c = pcToken.sourceChain) !== null && _c !== void 0 ? _c : 'unknown'})`),
|
|
634
|
+
chain: pcToken.sourceChain,
|
|
635
|
+
symbol: pcToken.symbol,
|
|
636
|
+
decimals: pcToken.decimals,
|
|
637
|
+
network,
|
|
638
|
+
};
|
|
628
639
|
}
|
|
629
|
-
// Infer origin chain
|
|
640
|
+
// Infer origin chain, symbol, decimals by matching against MOVEABLE_TOKENS
|
|
630
641
|
let originChain;
|
|
631
642
|
let tokenSymbol;
|
|
643
|
+
let tokenDecimals;
|
|
632
644
|
if ('symbol' in token) {
|
|
633
645
|
// MoveableToken path: infer chain by symbol + address
|
|
634
646
|
for (const [key, list] of Object.entries(tokens_1.MOVEABLE_TOKENS)) {
|
|
635
647
|
const k = key;
|
|
636
|
-
const
|
|
637
|
-
if (
|
|
648
|
+
const match = (list !== null && list !== void 0 ? list : []).find((t) => t.symbol === token.symbol && t.address === token.address);
|
|
649
|
+
if (match) {
|
|
638
650
|
originChain = k;
|
|
639
|
-
tokenSymbol =
|
|
651
|
+
tokenSymbol = match.symbol;
|
|
652
|
+
tokenDecimals = match.decimals;
|
|
640
653
|
break;
|
|
641
654
|
}
|
|
642
655
|
}
|
|
@@ -644,17 +657,20 @@ Utils.tokens = {
|
|
|
644
657
|
else {
|
|
645
658
|
// { chain, address } path: trust the provided chain and resolve symbol via registry
|
|
646
659
|
originChain = token.chain;
|
|
647
|
-
const list = (
|
|
648
|
-
const match =
|
|
660
|
+
const list = (_d = tokens_1.MOVEABLE_TOKENS[originChain]) !== null && _d !== void 0 ? _d : [];
|
|
661
|
+
const match = list.find((t) => t.address === token.address);
|
|
649
662
|
if (match) {
|
|
650
663
|
tokenSymbol = match.symbol;
|
|
664
|
+
tokenDecimals = match.decimals;
|
|
651
665
|
}
|
|
652
666
|
}
|
|
653
|
-
if (!originChain || !tokenSymbol) {
|
|
667
|
+
if (!originChain || !tokenSymbol || tokenDecimals === undefined) {
|
|
654
668
|
throw new Error('Unable to infer origin chain or token symbol for token');
|
|
655
669
|
}
|
|
656
|
-
const network = (_b = options === null || options === void 0 ? void 0 : options.network) !== null && _b !== void 0 ? _b : enums_1.PUSH_NETWORK.TESTNET_DONUT;
|
|
657
670
|
const map = chain_1.SYNTHETIC_PUSH_ERC20[network];
|
|
671
|
+
if (!map) {
|
|
672
|
+
throw new Error(`No PRC20 address map configured for network: ${network}`);
|
|
673
|
+
}
|
|
658
674
|
// Map token → synthetic key by origin chain family
|
|
659
675
|
const isEthFamily = originChain === enums_1.CHAIN.ETHEREUM_MAINNET ||
|
|
660
676
|
originChain === enums_1.CHAIN.ETHEREUM_SEPOLIA;
|
|
@@ -716,7 +732,13 @@ Utils.tokens = {
|
|
|
716
732
|
default:
|
|
717
733
|
throw new Error(`Unsupported token symbol: ${tokenSymbol}`);
|
|
718
734
|
}
|
|
719
|
-
return
|
|
735
|
+
return {
|
|
736
|
+
address: assertDeployed(map[key], `${tokenSymbol} on ${originChain}`),
|
|
737
|
+
chain: originChain,
|
|
738
|
+
symbol: tokenSymbol,
|
|
739
|
+
decimals: tokenDecimals,
|
|
740
|
+
network,
|
|
741
|
+
};
|
|
720
742
|
},
|
|
721
743
|
};
|
|
722
744
|
//# sourceMappingURL=utils.js.map
|