Skip to content

Commit

Permalink
Merge pull request #51 from ComposableFi/kirina/add-address-network
Browse files Browse the repository at this point in the history
Kirina/add address network
  • Loading branch information
nahyunbak authored Jan 21, 2025
2 parents 7f385be + 6a9123c commit 1cdb88d
Show file tree
Hide file tree
Showing 41 changed files with 4,753 additions and 3,460 deletions.
9 changes: 8 additions & 1 deletion dist/chains/common/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ interface Hop {
receiver?: string;
}
export declare const getForbiddenChains: (fromChainId: string, toChainId: string) => boolean;
/**@description Function to find the shortest path with channel information */
export declare const buildIbcPath: (fromChainId: string, toChainId: string) => Hop[];
/**@description Function to find the allowed tokens for the entire path */
export declare const getAllowedTokensForPath: (originChainId: string, destinationChainId: string) => any[];
export declare const channelList: import("../../config").NetworkInfo[];
export declare const getChainIdsByChannels: (channels: number[]) => string[];
/**@description If it returns undefined, that means it is not supported */
Expand All @@ -37,6 +40,10 @@ export declare const getXcmInfo: (fromChainId: string, toChainId: string) => {
tokens: string[];
};
export declare const getExplorerUrl: (chainId: string, infoType: "tx" | "address", info: string) => string;
export declare const getNetworkFromAddress: (address: string) => any;
export declare const getPolkadotAddressNetwork: (accountId: string) => string;
export declare const getCosmosAddressNetwork: (accountId: string) => string;
export declare const getSolanaAddressNetwork: (accountId: string) => string;
export declare const getEthereumAddressNetwork: (accountId: string) => string;
export declare const getNetworkFromAddress: (address: string) => string;
export {};
//# sourceMappingURL=utils.d.ts.map
2 changes: 1 addition & 1 deletion dist/chains/common/utils.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 73 additions & 28 deletions dist/chains/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNetworkFromAddress = exports.getExplorerUrl = exports.getXcmInfo = exports.getSourceChannel = exports.getChannelIdsFromMemo = exports.createForwardPathRecursive = exports.convertAddressToStr = exports.convertCosmosAddress = exports.getPolkadotAddressStr = exports.getSupportedType = exports.getChainIdsByChannels = exports.channelList = exports.buildIbcPath = exports.getForbiddenChains = exports.findSourceChannelId = exports.getTimeOut = exports.memoBuilder = exports.emitter = void 0;
exports.getNetworkFromAddress = exports.getEthereumAddressNetwork = exports.getSolanaAddressNetwork = exports.getCosmosAddressNetwork = exports.getPolkadotAddressNetwork = exports.getExplorerUrl = exports.getXcmInfo = exports.getSourceChannel = exports.getChannelIdsFromMemo = exports.createForwardPathRecursive = exports.convertAddressToStr = exports.convertCosmosAddress = exports.getPolkadotAddressStr = exports.getSupportedType = exports.getChainIdsByChannels = exports.channelList = exports.getAllowedTokensForPath = exports.buildIbcPath = exports.getForbiddenChains = exports.findSourceChannelId = exports.getTimeOut = exports.memoBuilder = exports.emitter = void 0;
var eventemitter3_1 = __importDefault(require("eventemitter3"));
var big_js_1 = __importDefault(require("big.js"));
var config_1 = require("../../config");
Expand All @@ -38,7 +38,6 @@ var cosmos_1 = require("../cosmos");
exports.emitter = new eventemitter3_1.default();
var bech32_1 = require("bech32");
var solana_1 = require("../solana");
var web3_1 = __importDefault(require("web3"));
var memoBuilder = function (_a) {
var destChannel = _a.destChannel, destAddress = _a.destAddress;
return JSON.stringify({
Expand Down Expand Up @@ -73,7 +72,7 @@ var getForbiddenChains = function (fromChainId, toChainId) {
return false;
};
exports.getForbiddenChains = getForbiddenChains;
// Function to find the shortest path with channel information
/**@description Function to find the shortest path with channel information */
var buildIbcPath = function (fromChainId, toChainId) {
if ((0, exports.getForbiddenChains)(fromChainId, toChainId))
return null;
Expand Down Expand Up @@ -113,6 +112,35 @@ var buildIbcPath = function (fromChainId, toChainId) {
return null;
};
exports.buildIbcPath = buildIbcPath;
/**@description Function to find the allowed tokens for the entire path */
var getAllowedTokensForPath = function (originChainId, destinationChainId) {
var _a, _b, _c, _d;
var result = (0, exports.buildIbcPath)(originChainId, destinationChainId);
console.log(result);
var supportedType = (0, exports.getSupportedType)(originChainId, destinationChainId);
if (supportedType === 'xcm') {
var xcmInfo = (0, exports.getXcmInfo)(originChainId, destinationChainId);
return xcmInfo.tokens;
}
if (!!supportedType) {
return result.reduce(function (acc, item) {
if (acc.length > 0) {
acc = acc.filter(function (token) {
return config_1.tokensPerChannel[item.chainId][item.channelId].tokens.includes(token);
});
}
else {
acc = __spreadArray([], __read(config_1.tokensPerChannel[item.chainId][item.channelId].tokens), false);
}
return acc;
}, []);
}
if (((_b = (_a = config_1.networks === null || config_1.networks === void 0 ? void 0 : config_1.networks[originChainId]) === null || _a === void 0 ? void 0 : _a.polkadot) === null || _b === void 0 ? void 0 : _b.relayChain) === 'polkadot' ||
((_d = (_c = config_1.networks === null || config_1.networks === void 0 ? void 0 : config_1.networks[destinationChainId]) === null || _c === void 0 ? void 0 : _c.polkadot) === null || _d === void 0 ? void 0 : _d.relayChain) === 'polkadot')
return ['DOT'];
return [];
};
exports.getAllowedTokensForPath = getAllowedTokensForPath;
exports.channelList = Object.values(config_1.networks);
var getChainIdsByChannels = function (channels) {
var _a, _b;
Expand Down Expand Up @@ -288,41 +316,58 @@ var getExplorerUrl = function (chainId, infoType, info) {
}
};
exports.getExplorerUrl = getExplorerUrl;
var getNetworkFromAddress = function (address) {
var getPolkadotAddressNetwork = function (accountId) {
var _a;
var ret = null;
//solana
try {
(0, solana_1.getPublicKey)(address);
return 'solana';
return (((_a = Object.values(config_1.networks).find(function (v) {
var _a;
var encoded = (0, util_crypto_1.encodeAddress)((0, util_crypto_1.decodeAddress)(accountId), (_a = v.polkadot) === null || _a === void 0 ? void 0 : _a.ss58Format);
if (encoded === accountId)
return v.chainId;
})) === null || _a === void 0 ? void 0 : _a.chainId) || '');
}
catch (_b) { }
// cosmos
catch (e) {
return '';
}
};
exports.getPolkadotAddressNetwork = getPolkadotAddressNetwork;
var getCosmosAddressNetwork = function (accountId) {
var found = '';
try {
var decoded_1 = bech32_1.bech32.decode(address);
var decoded_1 = bech32_1.bech32.decode(accountId);
Object.values(config_1.keplrChains).forEach(function (v) {
if (v.bech32Config.bech32PrefixAccAddr === decoded_1.prefix)
ret = v.chainId;
found = v.chainId;
});
return ret;
return found;
}
catch (_c) { }
// ethereum
try {
if (web3_1.default.utils.isAddress(address))
return 'ethereum';
catch (e) {
return found;
}
catch (_d) { }
//polkadot
};
exports.getCosmosAddressNetwork = getCosmosAddressNetwork;
var getSolanaAddressNetwork = function (accountId) {
try {
return (_a = Object.values(config_1.networks).find(function (v) {
var _a;
var encoded = (0, util_crypto_1.encodeAddress)((0, util_crypto_1.decodeAddress)(address), (_a = v.polkadot) === null || _a === void 0 ? void 0 : _a.ss58Format);
if (encoded === address)
return v.chainId;
})) === null || _a === void 0 ? void 0 : _a.chainId;
(0, solana_1.getPublicKey)(accountId); //triggers error if not valid
return 'solana';
}
catch (_e) { }
return null;
catch (e) {
return '';
}
};
exports.getSolanaAddressNetwork = getSolanaAddressNetwork;
var getEthereumAddressNetwork = function (accountId) {
if (accountId.startsWith('0x')) {
return 'ethereum';
}
return '';
};
exports.getEthereumAddressNetwork = getEthereumAddressNetwork;
var getNetworkFromAddress = function (address) {
var ethereumNetwork = (0, exports.getEthereumAddressNetwork)(address);
var cosmosNetwork = (0, exports.getCosmosAddressNetwork)(address);
var solanaNetwork = (0, exports.getSolanaAddressNetwork)(address);
var polkadotNetwork = (0, exports.getPolkadotAddressNetwork)(address);
return (ethereumNetwork || cosmosNetwork || solanaNetwork || polkadotNetwork || '');
};
exports.getNetworkFromAddress = getNetworkFromAddress;
1 change: 0 additions & 1 deletion dist/chains/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export * from './common';
export * from './cosmos';
export * from './ethereum';
export * from './solana';
export * from './polkadot';
//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion dist/chains/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dist/chains/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ __exportStar(require("./common"), exports);
__exportStar(require("./cosmos"), exports);
__exportStar(require("./ethereum"), exports);
__exportStar(require("./solana"), exports);
__exportStar(require("./polkadot"), exports);
2 changes: 1 addition & 1 deletion dist/chains/polkadot/helper.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1cdb88d

Please sign in to comment.