Skip to content

Commit

Permalink
Merge pull request #23 from ComposableFi/kirina/fix-polkadot-config
Browse files Browse the repository at this point in the history
Kirina/fix polkadot config
  • Loading branch information
nahyunbak authored Sep 17, 2024
2 parents 476b43d + 3b55bf1 commit 341bb44
Show file tree
Hide file tree
Showing 276 changed files with 50,457 additions and 3,685 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run generate-helper
npm run generate-helper & npm run generate-multihop
7 changes: 7 additions & 0 deletions dist/chains/common/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@ export declare const convertCosmosAddress: (address: string, newPrefix: string)
/**@description When it comes to Cosmos network, coinType should be 114 to use this converter*/
export declare const convertAddressToStr: (address: string, fromChainId: string) => string;
export declare const createForwardPathRecursive: (ibcPath: Hop[], index?: number, timeout?: number) => any;
export declare const getSourceChannel: (fromChainId: string, toChainId: string) => string;
export declare const getXcmInfo: (fromChainId: string, toChainId: string) => {
type: "XCM";
xcmType: string;
version: string;
tokens: 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.

69 changes: 56 additions & 13 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.createForwardPathRecursive = exports.convertAddressToStr = exports.convertCosmosAddress = exports.getPolkadotAddressStr = exports.getSupportedType = exports.buildIbcPath = exports.getForbiddenChains = exports.findSourceChannelId = exports.getTimeOut = exports.memoBuilder = exports.emitter = void 0;
exports.getXcmInfo = exports.getSourceChannel = exports.createForwardPathRecursive = exports.convertAddressToStr = exports.convertCosmosAddress = exports.getPolkadotAddressStr = exports.getSupportedType = 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 Down Expand Up @@ -116,8 +116,7 @@ var getSupportedType = function (fromChainId, toChainId) {
var _a, _b;
if (fromChainId === toChainId || !fromChainId || !toChainId)
return;
if ((config_1.tokensPerChannel === null || config_1.tokensPerChannel === void 0 ? void 0 : config_1.tokensPerChannel[fromChainId]) &&
Object.values(config_1.tokensPerChannel === null || config_1.tokensPerChannel === void 0 ? void 0 : config_1.tokensPerChannel[fromChainId]).find(function (item) { return (item === null || item === void 0 ? void 0 : item.chainId) === toChainId; }))
if ((0, exports.getSourceChannel)(fromChainId, toChainId))
return 'channel';
//XCM tx
if (config_1.networks[fromChainId].polkadot &&
Expand All @@ -144,8 +143,8 @@ var getPolkadotAddressStr = function (accountId, prefix) {
exports.getPolkadotAddressStr = getPolkadotAddressStr;
var convertCosmosAddress = function (address, newPrefix) {
try {
var data = (0, encoding_1.fromBech32)(address).data;
return (0, encoding_1.toBech32)(newPrefix, data);
var data_1 = (0, encoding_1.fromBech32)(address).data;
return (0, encoding_1.toBech32)(newPrefix, data_1);
}
catch (e) {
throw new Error('유효하지 않은 Bech32 주소입니다.');
Expand Down Expand Up @@ -199,11 +198,55 @@ var createForwardPathRecursive = function (ibcPath, index, timeout) {
};
};
exports.createForwardPathRecursive = createForwardPathRecursive;
// 예시 데이터
var ibcPath = [
{ chainId: 'osmosis-1', channelId: 1279 },
{ chainId: 'centauri-1', channelId: 52 },
];
// 실행 예시
var result = (0, exports.createForwardPathRecursive)(ibcPath, 0);
console.log(JSON.stringify({ forward: result }, null, 2));
var getSourceChannel = function (fromChainId, toChainId) {
if (config_1.tokensPerChannel === null || config_1.tokensPerChannel === void 0 ? void 0 : config_1.tokensPerChannel[fromChainId])
return Object.keys(config_1.tokensPerChannel === null || config_1.tokensPerChannel === void 0 ? void 0 : config_1.tokensPerChannel[fromChainId]).find(function (key) { var _a; return ((_a = config_1.tokensPerChannel === null || config_1.tokensPerChannel === void 0 ? void 0 : config_1.tokensPerChannel[fromChainId][key]) === null || _a === void 0 ? void 0 : _a.chainId) === toChainId; });
};
exports.getSourceChannel = getSourceChannel;
var getXcmInfo = function (fromChainId, toChainId) {
var _a, _b, _c;
return (_c = (_b = (_a = config_1.networks === null || config_1.networks === void 0 ? void 0 : config_1.networks[fromChainId]) === null || _a === void 0 ? void 0 : _a.polkadot) === null || _b === void 0 ? void 0 : _b.hops) === null || _c === void 0 ? void 0 : _c[toChainId];
};
exports.getXcmInfo = getXcmInfo;
// export const getBatchPath = () => {
// const found = polkadotRoute(origin, destination);
// if (!found) return;
// const route = {
// ...found,
// paths: found.paths?.map((p) => {
// return {
// ...p,
// address:
// toWallet !== ''
// ? // if we have toWallet, normal multihop checking
// getAddressFromNetwork(
// p.chainName,
// pickMultihopWalletByHandler(
// fromWallet,
// toWallet,
// config.networks[p.chainName].handler
// )
// )
// : // else, if we have toAddres, check if the next hop is from or to
// toAddress !== undefined &&
// pickMultihopWalletByHandlerToAddress(
// fromWallet,
// config.networks[p.chainName].handler,
// toAddress
// ) === 'toAddress'
// ? // is toAddress, we need to generate the address for the chain
// getConvertedAddress({
// address: toAddress,
// network: p.chainName,
// })
// : // is fromWallet
// getAddressFromNetwork(p.chainName, fromWallet),
// // getAddressFromNetwork(
// // p.chainName,
// // // TODO: CHECK THIS
// // pickMultihopWalletByHandler(fromWallet, toWallet, config.networks[p.chainName].handler)
// // )
// };
// }),
// };
// };
4 changes: 4 additions & 0 deletions dist/chains/cosmos/helper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ export declare const getCosmosClient: ({ chainId, rpc, keplr, feeAssetId, gasPri
gasPrice: string;
supportLedger: boolean;
}) => Promise<SigningStargateClient>;
export declare const getCosmosBlockHeight: ({ client, extra, }: {
client: SigningStargateClient;
extra: number;
}) => Promise<number>;
//# sourceMappingURL=helper.d.ts.map
2 changes: 1 addition & 1 deletion dist/chains/cosmos/helper.d.ts.map

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

15 changes: 14 additions & 1 deletion dist/chains/cosmos/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCosmosClient = exports.getSigner = exports.getCosmosTimeoutTimestamp = exports.generateTransferMsg = void 0;
exports.getCosmosBlockHeight = exports.getCosmosClient = exports.getSigner = exports.getCosmosTimeoutTimestamp = exports.generateTransferMsg = void 0;
var stargate_1 = require("@cosmjs/stargate");
var generateTransferMsg = function (txMsg, channel, sourceAddress, destAddress, amount, assetId, memo, timeout) {
var msg = {
Expand Down Expand Up @@ -88,3 +88,16 @@ var getCosmosClient = function (_a) { return __awaiter(void 0, [_a], void 0, fun
});
}); };
exports.getCosmosClient = getCosmosClient;
var getCosmosBlockHeight = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
var _c;
var client = _b.client, _d = _b.extra, extra = _d === void 0 ? 100 : _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_c = Number;
return [4 /*yield*/, client.getHeight()];
case 1: return [2 /*return*/, _c.apply(void 0, [_e.sent()]) + extra];
}
});
}); };
exports.getCosmosBlockHeight = getCosmosBlockHeight;
2 changes: 2 additions & 0 deletions dist/chains/cosmos/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TX_MSG } from './constants';
export type TX_MSG_TYPE = typeof TX_MSG;
export { type Keplr, type OfflineAminoSigner } from '@keplr-wallet/types';
export { type IbcExtension } from '@cosmjs/stargate';
//# sourceMappingURL=types.d.ts.map
2 changes: 1 addition & 1 deletion dist/chains/cosmos/types.d.ts.map

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

1 change: 1 addition & 0 deletions dist/chains/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ 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: 1 addition & 0 deletions dist/chains/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ __exportStar(require("./common"), exports);
__exportStar(require("./cosmos"), exports);
__exportStar(require("./ethereum"), exports);
__exportStar(require("./solana"), exports);
__exportStar(require("./polkadot"), exports);
38 changes: 38 additions & 0 deletions dist/chains/polkadot/api-scheme/assets/definitions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
declare const _default: {
rpc: {
balanceOf: {
description: string;
params: ({
name: string;
type: string;
isOptional?: undefined;
} | {
name: string;
type: string;
isOptional: boolean;
})[];
type: string;
};
listAssets: {
description: string;
params: {
name: string;
type: string;
isOptional: boolean;
}[];
type: string;
};
};
types: {
Asset: {
name: string;
id: string;
decimals: string;
ratio: string;
foreignId: string;
existentialDeposit: string;
};
};
};
export default _default;
//# sourceMappingURL=definitions.d.ts.map

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

46 changes: 46 additions & 0 deletions dist/chains/polkadot/api-scheme/assets/definitions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = {
rpc: {
balanceOf: {
description: 'Balance available for the specified account for the specified asset.',
params: [
{
name: 'asset',
type: 'CustomRpcCurrencyId'
},
{
name: 'account',
type: 'AccountId32'
},
{
name: 'at',
type: 'Hash',
isOptional: true
}
],
type: 'CustomRpcBalance'
},
listAssets: {
description: 'Lists the available recognized assets for the runtime.',
params: [
{
name: 'at',
type: 'Hash',
isOptional: true
}
],
type: 'Vec<Asset>'
}
},
types: {
Asset: {
name: 'Vec<u8>',
id: 'u128',
decimals: 'u32',
ratio: 'Option<ComposableTraitsCurrencyRational64>',
foreignId: 'Option<XcmV1MultiLocation>',
existentialDeposit: 'CustomRpcBalance'
}
}
};
2 changes: 2 additions & 0 deletions dist/chains/polkadot/api-scheme/assets/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './types';
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions dist/chains/polkadot/api-scheme/assets/index.d.ts.map

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

18 changes: 18 additions & 0 deletions dist/chains/polkadot/api-scheme/assets/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./types"), exports);
13 changes: 13 additions & 0 deletions dist/chains/polkadot/api-scheme/assets/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Bytes, Option, Struct, u32 } from '@polkadot/types-codec';
import type { CustomRpcBalance } from '../common';
import type { ComposableTraitsCurrencyRational64, XcmV1MultiLocation } from '../crowdloanRewards';
/** @name Asset */
export interface Asset extends Struct {
readonly name: Bytes;
readonly id: Text;
readonly decimals: u32;
readonly ratio: Option<ComposableTraitsCurrencyRational64>;
readonly foreignId: Option<XcmV1MultiLocation>;
readonly existentialDeposit: CustomRpcBalance;
}
//# sourceMappingURL=types.d.ts.map
1 change: 1 addition & 0 deletions dist/chains/polkadot/api-scheme/assets/types.d.ts.map

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

2 changes: 2 additions & 0 deletions dist/chains/polkadot/api-scheme/assets/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Loading

0 comments on commit 341bb44

Please sign in to comment.