Skip to content

Commit

Permalink
Merge pull request #50 from ComposableFi/kirina/update-asset-limit
Browse files Browse the repository at this point in the history
Kirina/update asset limit
  • Loading branch information
nahyunbak authored Jan 2, 2025
2 parents ababcb5 + cf8e634 commit 7f385be
Show file tree
Hide file tree
Showing 23 changed files with 2,418 additions and 79 deletions.
2 changes: 1 addition & 1 deletion dist/chains/polkadot/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function signAndSendTransfer(_a) {
});
}); })
.catch(function (e) {
console.log('errorSDKSignAndSend', e);
console.error('errorSDKSignAndSend', e);
return reject({
fromAddress: fromAddress,
destAddress: toAddress,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "picasso-sdk",
"version": "0.3.175",
"version": "0.3.177",
"description": "Picasso sdk for cosmos, ethereum, solana, and polkadot ibc transfer",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
35 changes: 34 additions & 1 deletion src/chains/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const getForbiddenChains = (fromChainId: string, toChainId: string) => {
return true;
return false;
};
// Function to find the shortest path with channel information
/**@description Function to find the shortest path with channel information */
export const buildIbcPath = (fromChainId: string, toChainId: string): Hop[] => {
if (getForbiddenChains(fromChainId, toChainId)) return null;
// Set to keep track of visited chains
Expand Down Expand Up @@ -117,6 +117,39 @@ export const buildIbcPath = (fromChainId: string, toChainId: string): Hop[] => {
return null;
};

/**@description Function to find the allowed tokens for the entire path */
export const getAllowedTokensForPath = (
originChainId: string,
destinationChainId: string
) => {
const result = buildIbcPath(originChainId, destinationChainId);

console.log(result);
const supportedType = getSupportedType(originChainId, destinationChainId);
if (supportedType === 'xcm') {
const xcmInfo = getXcmInfo(originChainId, destinationChainId);
return xcmInfo.tokens;
}
if (!!supportedType) {
return result.reduce((acc, item) => {
if (acc.length > 0) {
acc = acc.filter((token) =>
tokensPerChannel[item.chainId][item.channelId].tokens.includes(token)
);
} else {
acc = [...tokensPerChannel[item.chainId][item.channelId].tokens];
}
return acc;
}, []);
}
if (
networks?.[originChainId]?.polkadot?.relayChain === 'polkadot' ||
networks?.[destinationChainId]?.polkadot?.relayChain === 'polkadot'
)
return ['DOT'];
return [];
};

export const channelList = Object.values(networks);

export const getChainIdsByChannels = (channels: number[]): string[] => {
Expand Down
16 changes: 16 additions & 0 deletions src/chains/polkadot/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@ async function signAndSendTransfer<T extends AnyTuple>({

return new Promise<TransferStatusByAddress>((resolve, reject) => {
const state = { isFailedTxShown: false };
console.log('step0', extrinsic);
extrinsic
.signAndSend(account, signerOption, async (result) => {
// Emit approval event
console.log('step1', result);

const { dispatchError, status, events } = result;
const { txHash, sequence } = buildStatusInfo(
result.txHash.toString(),
JSON.parse(JSON.stringify(events))
);

console.log('step2', events, txHash, sequence);
// Handle dispatch errors
if (dispatchError) {
let errorMessage;
Expand All @@ -88,11 +91,13 @@ async function signAndSendTransfer<T extends AnyTuple>({
};
return reject(errorResult);
}
console.log('step3', events);

// Look for incomplete transfer events
const found = JSON.parse(JSON.stringify(events)).find((e) =>
e.event?.data?.find((data) => data['incomplete']?.length > 0)
);
console.log('step4', found);

if (found) {
return reject({
Expand All @@ -106,7 +111,11 @@ async function signAndSendTransfer<T extends AnyTuple>({

// Check if transaction is finalized
if (status) {
console.log('step5', status);

if (isIbc) {
console.log('step5.5');

const header = apiTo ? await apiTo.rpc.chain.getHeader() : null;
const result: TransferStatusByAddress = {
destAddress: toAddress,
Expand All @@ -118,6 +127,8 @@ async function signAndSendTransfer<T extends AnyTuple>({
};
return resolve(result);
} else if (filter) {
console.log('step6');

const found = events.find((e) => filter(e.event));
if (!found && !state.isFailedTxShown) {
state.isFailedTxShown = true;
Expand All @@ -129,6 +140,8 @@ async function signAndSendTransfer<T extends AnyTuple>({
});
}
if (found && found.event.data.find((x) => x['isComplete'])) {
console.log('step6.5');

const result: TransferStatusByAddress = {
destAddress: toAddress,
txHash,
Expand All @@ -140,6 +153,8 @@ async function signAndSendTransfer<T extends AnyTuple>({
}
} else {
// For xTokens
console.log('step7');

const header = apiTo ? await apiTo.rpc.chain.getHeader() : null;
const result: TransferStatusByAddress = {
destAddress: toAddress,
Expand Down Expand Up @@ -168,6 +183,7 @@ async function signAndSendTransfer<T extends AnyTuple>({
}

export const buildStatusInfo = (txHash, events) => {
console.log('buildStatusInfo', events);
if (!events) return { txHash, sequence: 'NONE' };
const packet = events
.filter(
Expand Down
30 changes: 29 additions & 1 deletion src/config/json/agoric.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,35 @@
"55": {
"chainId": "centauri-1",
"destinationId": 13,
"tokens": ["BLD", "IST"]
"tokens": [
"PICA",
"ETH",
"DAI",
"FXS",
"sFRAX",
"sfrxETH",
"OSMO",
"ENA",
"FRAX",
"frxETH",
"wBTC",
"pxETH",
"PEPE",
"CRV",
"rETH",
"crvUSD",
"eETH",
"USDe",
"USDT Ethereum",
"stETH",
"ATOM",
"IST",
"stATOM",
"BLD",
"SEI",
"SCRT",
"STRD"
]
}
},
"currencies": [
Expand Down
30 changes: 29 additions & 1 deletion src/config/json/archway.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,35 @@
"108": {
"chainId": "centauri-1",
"destinationId": 50,
"tokens": ["ARCH"]
"tokens": [
"PICA",
"ETH",
"DAI",
"FXS",
"sFRAX",
"sfrxETH",
"OSMO",
"ENA",
"FRAX",
"frxETH",
"wBTC",
"pxETH",
"PEPE",
"CRV",
"rETH",
"crvUSD",
"eETH",
"USDe",
"USDT Ethereum",
"stETH",
"ATOM",
"IST",
"stATOM",
"BLD",
"SEI",
"SCRT",
"STRD"
]
}
},
"currencies": [
Expand Down
Loading

0 comments on commit 7f385be

Please sign in to comment.