Skip to content

Commit

Permalink
Merge pull request #21 from ComposableFi/kirina/fix-multihop
Browse files Browse the repository at this point in the history
Fix multihop util function, config
  • Loading branch information
nahyunbak authored Aug 30, 2024
2 parents 450bc93 + f5b96c4 commit 476b43d
Show file tree
Hide file tree
Showing 35 changed files with 2,089 additions and 1,451 deletions.
3 changes: 2 additions & 1 deletion dist/chains/common/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import EventEmitter from 'eventemitter3';
import { WalletApiEvents } from './types';
import { TransferType } from '../../config';
export declare const emitter: EventEmitter<WalletApiEvents, any>;
export declare const TIMEOUT_IBC_MAX = 6000000000000;
export declare const memoBuilder: ({ destChannel, destAddress, }: {
destChannel: number;
destAddress: string;
Expand All @@ -13,6 +12,7 @@ export declare const findSourceChannelId: (sourceChainId: string, destChainId: s
interface Hop {
chainId: string;
channelId: number;
receiver?: string;
}
export declare const getForbiddenChains: (fromChainId: string, toChainId: string) => boolean;
export declare const buildIbcPath: (fromChainId: string, toChainId: string) => Hop[];
Expand All @@ -22,5 +22,6 @@ export declare const getPolkadotAddressStr: (accountId: string, prefix?: number)
export declare const convertCosmosAddress: (address: string, newPrefix: string) => 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 {};
//# 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.

40 changes: 35 additions & 5 deletions dist/chains/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertAddressToStr = exports.convertCosmosAddress = exports.getPolkadotAddressStr = exports.getSupportedType = exports.buildIbcPath = exports.getForbiddenChains = exports.findSourceChannelId = exports.getTimeOut = exports.memoBuilder = exports.TIMEOUT_IBC_MAX = exports.emitter = void 0;
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");
var encoding_1 = require("@cosmjs/encoding");
var util_crypto_1 = require("@polkadot/util-crypto");
var cosmos_1 = require("../cosmos");
exports.emitter = new eventemitter3_1.default();
exports.TIMEOUT_IBC_MAX = 6000000000000;
var memoBuilder = function (_a) {
var destChannel = _a.destChannel, destAddress = _a.destAddress;
return JSON.stringify({
forward: {
receiver: destAddress,
port: 'transfer',
channel: "channel-".concat(destChannel),
timeout: exports.TIMEOUT_IBC_MAX,
timeout: cosmos_1.TIMEOUT_IBC_MAX,
retries: 0,
},
});
Expand Down Expand Up @@ -144,9 +144,7 @@ var getPolkadotAddressStr = function (accountId, prefix) {
exports.getPolkadotAddressStr = getPolkadotAddressStr;
var convertCosmosAddress = function (address, newPrefix) {
try {
// Bech32 주소를 디코딩하여 5바이트 접두사 제거
var data = (0, encoding_1.fromBech32)(address).data;
// 새로운 접두사로 다시 Bech32 주소 생성
return (0, encoding_1.toBech32)(newPrefix, data);
}
catch (e) {
Expand Down Expand Up @@ -177,3 +175,35 @@ var convertAddressToStr = function (address, fromChainId) {
return address;
};
exports.convertAddressToStr = convertAddressToStr;
var createForwardPathRecursive = function (ibcPath, index, timeout) {
if (index === void 0) { index = 0; }
if (timeout === void 0) { timeout = cosmos_1.TIMEOUT_IBC_MAX; }
if (index === ibcPath.length - 1) {
return {
receiver: ibcPath[index].receiver,
port: 'transfer',
channel: "channel-".concat(ibcPath[index].channelId),
timeout: timeout,
retries: 0,
};
}
return {
receiver: ibcPath[index].receiver,
port: 'transfer',
channel: "channel-".concat(ibcPath[index].channelId),
timeout: timeout,
retries: 0,
next: {
forward: (0, exports.createForwardPathRecursive)(ibcPath, index + 1),
},
};
};
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));
1 change: 1 addition & 0 deletions dist/chains/cosmos/constants.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export declare const TX_MSG = "/ibc.applications.transfer.v1.MsgTransfer";
export declare const TIMEOUT_IBC_MAX = 6000000000000;
//# sourceMappingURL=constants.d.ts.map
2 changes: 1 addition & 1 deletion dist/chains/cosmos/constants.d.ts.map

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

3 changes: 2 additions & 1 deletion dist/chains/cosmos/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TX_MSG = void 0;
exports.TIMEOUT_IBC_MAX = exports.TX_MSG = void 0;
exports.TX_MSG = '/ibc.applications.transfer.v1.MsgTransfer';
exports.TIMEOUT_IBC_MAX = 6000000000000;
2 changes: 1 addition & 1 deletion dist/chains/cosmos/methods.d.ts.map

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

21 changes: 8 additions & 13 deletions dist/chains/cosmos/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.cosmosTransfer = void 0;
var utils_1 = require("../common/utils");
var constants_1 = require("./constants");
var helper_1 = require("./helper");
var cosmosTransfer = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
Expand All @@ -56,9 +55,7 @@ var cosmosTransfer = function (_a) { return __awaiter(void 0, [_a], void 0, func
case 1:
client = _d.sent();
msg = (0, helper_1.generateTransferMsg)(txMsg, sourceChannel, sourceAddress, destAddress, amount, assetId, memo, timeout);
return [4 /*yield*/, client.simulate(sourceAddress, [msg], memo)];
case 2:
_d.sent();
// await client.simulate(sourceAddress, [msg], memo);
// To avoid keplr or leap overrides custom fee from FE (mostly it is set to 'auto'
if (keplr) {
keplr.defaultOptions = {
Expand All @@ -78,20 +75,18 @@ var cosmosTransfer = function (_a) { return __awaiter(void 0, [_a], void 0, func
],
gas: gas,
};
_d.label = 3;
case 3:
_d.trys.push([3, 5, , 6]);
_d.label = 2;
case 2:
_d.trys.push([2, 4, , 5]);
return [4 /*yield*/, client.signAndBroadcast(sourceAddress, [msg], refinedFee)];
case 4:
case 3:
generalResponse = _d.sent();
utils_1.emitter.emit('COSMOS_APPROVED'); // optional: emit event for approval of wallet extension
return [2 /*return*/, generalResponse.transactionHash]; // Query indexer by this txHash
case 5:
case 4:
ex_1 = _d.sent();
console.error(ex_1, 'cosmosError');
utils_1.emitter.emit('CANCEL_COSMOS'); // optional: emit event for cancel of wallet extension
return [3 /*break*/, 6];
case 6: return [2 /*return*/];
return [3 /*break*/, 5];
case 5: return [2 /*return*/];
}
});
}); };
Expand Down
168 changes: 84 additions & 84 deletions dist/config/coinGecko.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,6 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.coinGecko = void 0;
exports.coinGecko = [
{
"name": "ASTR",
"id": "astar"
},
{
"name": "DOT",
"id": "polkadot"
},
{
"name": "BNC_DOT",
"id": "bifrost-native-coin"
},
{
"name": "ASTR",
"id": "astar"
},
{
"name": "KSM",
"id": "kusama"
},
{
"name": "GLMR",
"id": "moonbeam"
},
{
"name": "MOVR",
"id": "moonriver"
},
{
"name": "USDT Kusama",
"id": "tether"
},
{
"name": "TNKR",
"id": "tinkernet"
},
{
"name": "KSM",
"id": "kusama"
},
{
"name": "BNC_KSM",
"id": "bifrost-native-coin"
},
{
"name": "KSM",
"id": "kusama"
},
{
"name": "SDN",
"id": "shiden"
},
{
"name": "TNKR",
"id": "tinkernet"
},
{
"name": "BLD",
"id": "agoric"
Expand All @@ -70,22 +14,10 @@ exports.coinGecko = [
"name": "ARCH",
"id": "archway"
},
{
"name": "BNC_KSM",
"id": "bifrost-native-coin"
},
{
"name": "BNC_DOT",
"id": "bifrost-native-coin"
},
{
"name": "TIA",
"id": "celestia"
},
{
"name": "PICA",
"id": "picasso"
},
{
"name": "HUAHUA",
"id": "chihuahua-token"
Expand Down Expand Up @@ -198,14 +130,6 @@ exports.coinGecko = [
"name": "KUJI",
"id": "kujira"
},
{
"name": "USDT Kusama",
"id": "tether"
},
{
"name": "USDT Kusama",
"id": "tether"
},
{
"name": "ASTRO",
"id": "astroport-fi"
Expand All @@ -214,14 +138,6 @@ exports.coinGecko = [
"name": "NTRN",
"id": "neutron-3"
},
{
"name": "OSMO",
"id": "osmosis"
},
{
"name": "milkTIA",
"id": "milkyway-staked-tia"
},
{
"name": "QCK",
"id": "quicksilver"
Expand Down Expand Up @@ -262,6 +178,90 @@ exports.coinGecko = [
"name": "UMEE",
"id": "umee"
},
{
"name": "ASTR",
"id": "astar"
},
{
"name": "DOT",
"id": "polkadot"
},
{
"name": "BNC_DOT",
"id": "bifrost-native-coin"
},
{
"name": "ASTR",
"id": "astar"
},
{
"name": "KSM",
"id": "kusama"
},
{
"name": "GLMR",
"id": "moonbeam"
},
{
"name": "MOVR",
"id": "moonriver"
},
{
"name": "USDT Kusama",
"id": "tether"
},
{
"name": "TNKR",
"id": "tinkernet"
},
{
"name": "KSM",
"id": "kusama"
},
{
"name": "BNC_KSM",
"id": "bifrost-native-coin"
},
{
"name": "KSM",
"id": "kusama"
},
{
"name": "SDN",
"id": "shiden"
},
{
"name": "TNKR",
"id": "tinkernet"
},
{
"name": "BNC_KSM",
"id": "bifrost-native-coin"
},
{
"name": "BNC_DOT",
"id": "bifrost-native-coin"
},
{
"name": "PICA",
"id": "picasso"
},
{
"name": "USDT Kusama",
"id": "tether"
},
{
"name": "USDT Kusama",
"id": "tether"
},
{
"name": "OSMO",
"id": "osmosis"
},
{
"name": "milkTIA",
"id": "milkyway-staked-tia"
},
{
"name": "SOL",
"id": "solana"
Expand Down
2 changes: 1 addition & 1 deletion dist/config/crossChainAssets.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 476b43d

Please sign in to comment.