Skip to content

Commit

Permalink
Merge pull request #9 from ComposableFi/kirina/fix-issues
Browse files Browse the repository at this point in the history
Fix integration issue
  • Loading branch information
nahyunbak authored Jul 2, 2024
2 parents 17d3f42 + 0a20553 commit d985b83
Show file tree
Hide file tree
Showing 86 changed files with 12,300 additions and 11,833 deletions.
6 changes: 6 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
};
84 changes: 30 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,54 @@
# picasso-sdk
This is Picasso IBC sdk for cosmos, ethereum, solana, and polkadot(will be updated soon)

# How to use indexer
This is Picasso IBC sdk for cosmos, ethereum, solana, and polkadot(will be updated soon)

### 1. Transaction with direct channel
* You can query indexer [API](https://204.48.25.128/api/ibc_events?txHash=0F3DFE07428C1D600964B5FA9BF91A72EEEED0AFB628532864998B58F97B66A7) with transaction hash
# How to use indexer

### 1. Transaction with direct channel

- You can query indexer [API](https://204.48.25.128/api/ibc_events?txHash=0F3DFE07428C1D600964B5FA9BF91A72EEEED0AFB628532864998B58F97B66A7) with transaction hash

### 2. PFM
* You can query status using next hop's information

* example : Composable -> Picasso cosmos
- You can query status using next hop's information

- example : Composable -> Picasso cosmos

1. [Composable -> Picasso (kusama)](https://204.48.25.128/api/ibc_events?fromBlockHash=0x2cfdd9d31db4c1c5b643c7b8a82cdf7e65fcd4b711fa2745e67ee448a69980db&sequence=4823)

```
[response]
{
...,
...,
toBlockHash : "0xde232ee07fb9d6c36f4f3c04ae3dca1be02890f4f2cbe369d730c25a2083e831",
nextSequence : "21892"
}
```

2. [Picasso (kusama) -> Picasso(Cosmos)](https://204.48.25.128/api/ibc_events?fromBlockHash=0xde232ee07fb9d6c36f4f3c04ae3dca1be02890f4f2cbe369d730c25a2083e831&sequence=21892)

```
[response]
[response]
{
...,
...,
toBlockHash : "C209A7397B3A0C139F5959C48035224AB7048718920CED667AB84DCFEF7FE4F4",
nextSequence : "null" // query until nextSequence is null
nextSequence : "null" // query until nextSequence is null
}
```



# How to use methods

### Ethereum
```
import React from 'react';
import Big from 'big.js';
import { memoBuilder, getApprovedErc20, getWeb3, approveErc20, ethereumTransfer } from 'picasso-sdk';
### Ethereum

```
const web3 = getWeb3('endpoint');
const AMOUNT = '10000000000000000'; // hardcoded example
// use txhash to track the transaction from indexer
const Button = () => {
const EthereumButton = () => {
//example : send ETH osmosis -> solana transfer via picasso pfm
const AMOUNT = '10000000000000000'; // hardcoded example
// example txhash: ethereum -> picasso https://etherscan.io/tx/0x6c3fd9120cfe7825d98e41e5b71279cfd6543c3811d82e40545ca7e69a2d95ce
const ethereumToPicassoTransfer = async () => {
//TODO: add approval
Expand All @@ -62,12 +60,13 @@ const Button = () => {
destinationAddress: 'pica1ewm97t5qw3uutwd9qh0ydy007ymhl8qth56qlj',
channel: 2, // etheruem to picasso(cosmos) channel is 2
minimalDenom: 'ETH', // for PICA it is 'transfer/channel-2/ppica'
memo: ''
memo: '',
timeout: 240
});
console.log(txHash, 'txHash:Ethereum->Picasso');
};
// example txHash: ethereum -> archway https://etherscan.io/tx/0x332d9cd30af18245e5a70989f0e61a0f98594ca25baf159ab409223b808c4744
// example txHash: ethereum -> archway https://etherscan.io/tx/0x332d9cd30af18245e5a70989f0e61a0f98594ca25baf159ab409223b808c4744
// send PICA from ethereum to osmosis
const ethereumPfmTransfer = async () => {
const approvedAmount = await getApprovedErc20(
Expand All @@ -77,13 +76,11 @@ const Button = () => {
); // PICA's erc20 address
if (new Big(approvedAmount || 0).lt(AMOUNT)) {
await approveErc20({
web3
}
web3,
'0xbb63a9b64a80e9338b8ea298c51765e57c4f159c',
AMOUNT,
'0xbb63a9b64a80e9338b8ea298c51765e57c4f159c'
);
account: '0xbb63a9b64a80e9338b8ea298c51765e57c4f159c',
amount: AMOUNT,
erc20TokenAddress: '0x3432b6a60d23ca0dfca7761b7ab56459d9c964d0' // FXS's erc20 address
});
}
// ethereum memo should use escape code
Expand Down Expand Up @@ -115,21 +112,12 @@ const Button = () => {
);
};
export default Button;
```

### Solana


### Solana
```
import React from 'react';
import { getTimeOut, memoBuilder, solanaTransfer } from 'picasso-sdk';
// use txhash to track the transaction from indexer
const Button = () => {
const SolanaButton = () => {
//example : osmosis -> picasso transfer
const solanaToPicassoTransfer = async () => {
//rewrite below code to use solanaTransfer method
Expand Down Expand Up @@ -176,21 +164,12 @@ const Button = () => {
</>
);
};
export default Button;
```


### Cosmos
```
import React from 'react';

import { memoBuilder, cosmosTransfer } from 'picasso-sdk';
// use txhash to track the transaction from indexer
const Button = () => {
```
const CosmosButton = () => {
//example : osmosis -> solana transfer via picasso pfm
const cosmosToSolanaTransfer = async () => {
const txHash = await cosmosTransfer({
Expand Down Expand Up @@ -235,7 +214,4 @@ const Button = () => {
</>
);
};
export default Button;
```
2 changes: 1 addition & 1 deletion dist/chains/common/index.d.ts.map

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

2 changes: 1 addition & 1 deletion dist/chains/common/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export type WalletApiEvents = 'COSMOS_APPROVED' | 'CANCEL_COSMOS' | 'SOLANA_APPROVED' | 'CANCEL_SOLANA' | 'ETHEREUM_APPROVED' | "CANCEL_ETHEREUM";
export type WalletApiEvents = 'COSMOS_APPROVED' | 'CANCEL_COSMOS' | 'SOLANA_APPROVED' | 'CANCEL_SOLANA' | 'ETHEREUM_APPROVED' | 'CANCEL_ETHEREUM';
//# sourceMappingURL=types.d.ts.map
2 changes: 1 addition & 1 deletion dist/chains/common/types.d.ts.map

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

6 changes: 3 additions & 3 deletions dist/chains/common/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import EventEmitter from "eventemitter3";
import { WalletApiEvents } from "./types";
import EventEmitter from 'eventemitter3';
import { WalletApiEvents } from './types';
export declare const emitter: EventEmitter<WalletApiEvents, any>;
export declare const TIMEOUT_IBC_MAX = 6000000000000;
export declare const memoBuilder: ({ destChannel, destAddress }: {
export declare const memoBuilder: ({ destChannel, destAddress, }: {
destChannel: number;
destAddress: string;
}) => string;
Expand Down
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.

6 changes: 3 additions & 3 deletions dist/chains/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.getTimeOut = exports.memoBuilder = exports.TIMEOUT_IBC_MAX = exports.emitter = void 0;
var eventemitter3_1 = __importDefault(require("eventemitter3"));
var big_js_1 = __importDefault(require("big.js"));
exports.emitter = new eventemitter3_1.default;
exports.emitter = new eventemitter3_1.default();
exports.TIMEOUT_IBC_MAX = 6000000000000;
var memoBuilder = function (_a) {
var destChannel = _a.destChannel, destAddress = _a.destAddress;
Expand All @@ -16,8 +16,8 @@ var memoBuilder = function (_a) {
port: 'transfer',
channel: "channel-".concat(destChannel),
timeout: exports.TIMEOUT_IBC_MAX,
retries: 0
}
retries: 0,
},
});
};
exports.memoBuilder = memoBuilder;
Expand Down
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.

13 changes: 10 additions & 3 deletions dist/chains/cosmos/helper.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SigningStargateClient } from '@cosmjs/stargate';
import { TX_MSG_TYPE } from './types';
import { type Keplr } from '@keplr-wallet/types';
export declare const generateTransferMsg: (txMsg: TX_MSG_TYPE, channel: number, sourceAddress: string, destAddress: string, amount: string, assetId: string, memo: string, timeout?: number) => {
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer";
value: {
Expand All @@ -18,7 +19,13 @@ export declare const generateTransferMsg: (txMsg: TX_MSG_TYPE, channel: number,
/** description the amount of seconds for timeout */
export declare const getCosmosTimeoutTimestamp: (seconds: number) => number;
/** @description chainId is from cosmos chain registry */
export declare const getSigner: (chainId: string) => any;
export declare const keplr: any;
export declare const getClient: (chainId: string, rpc: string) => Promise<SigningStargateClient>;
export declare const getSigner: (chainId: string, keplr: Keplr, supportLedger?: boolean) => import("@keplr-wallet/types").OfflineAminoSigner;
export declare const getClient: ({ chainId, rpc, keplr, feeAssetId, gasPrice, supportLedger, }: {
chainId: string;
rpc: string;
keplr: Keplr;
feeAssetId: string;
gasPrice: string;
supportLedger: boolean;
}) => Promise<SigningStargateClient>;
//# 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.

36 changes: 22 additions & 14 deletions 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.getClient = exports.keplr = exports.getSigner = exports.getCosmosTimeoutTimestamp = exports.generateTransferMsg = void 0;
exports.getClient = 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) {
if (timeout === void 0) { timeout = 30; }
Expand All @@ -47,13 +47,13 @@ var generateTransferMsg = function (txMsg, channel, sourceAddress, destAddress,
sourceChannel: "channel-".concat(channel),
token: {
denom: assetId,
amount: amount
amount: amount,
},
sender: sourceAddress,
receiver: destAddress,
memo: memo,
timeoutTimestamp: (0, exports.getCosmosTimeoutTimestamp)(timeout * 60) // 30~240 minutes
}
timeoutTimestamp: (0, exports.getCosmosTimeoutTimestamp)(timeout * 60), // 30~240 minutes
},
};
return msg;
};
Expand All @@ -64,19 +64,27 @@ var getCosmosTimeoutTimestamp = function (seconds) {
};
exports.getCosmosTimeoutTimestamp = getCosmosTimeoutTimestamp;
/** @description chainId is from cosmos chain registry */
var getSigner = function (chainId) {
return exports.keplr === null || exports.keplr === void 0 ? void 0 : exports.keplr.getOfflineSigner(chainId);
var getSigner = function (chainId, keplr, supportLedger) {
if (supportLedger === void 0) { supportLedger = true; }
return supportLedger
? keplr.getOfflineSignerOnlyAmino(chainId)
: keplr.getOfflineSigner(chainId);
};
exports.getSigner = getSigner;
exports.keplr = (typeof window !== 'undefined') ? window.keplr : undefined; // provider of cosmos wallet
var getClient = function (chainId, rpc) { return __awaiter(void 0, void 0, void 0, function () {
var signer;
return __generator(this, function (_a) {
switch (_a.label) {
// export const keplr = (typeof window !== 'undefined') ? (window as any).keplr : undefined; // provider of cosmos wallet
var getClient = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
var signer, finalClient;
var chainId = _b.chainId, rpc = _b.rpc, keplr = _b.keplr, feeAssetId = _b.feeAssetId, gasPrice = _b.gasPrice, _c = _b.supportLedger, supportLedger = _c === void 0 ? true : _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
signer = (0, exports.getSigner)(chainId);
return [4 /*yield*/, stargate_1.SigningStargateClient.connectWithSigner(rpc, signer)];
case 1: return [2 /*return*/, _a.sent()];
signer = (0, exports.getSigner)(chainId, keplr, supportLedger);
return [4 /*yield*/, stargate_1.SigningStargateClient.connectWithSigner(rpc, signer, {
gasPrice: stargate_1.GasPrice.fromString("".concat(gasPrice).concat(feeAssetId)),
})];
case 1:
finalClient = _d.sent();
return [2 /*return*/, finalClient];
}
});
}); };
Expand Down
2 changes: 1 addition & 1 deletion dist/chains/cosmos/index.d.ts.map

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

10 changes: 7 additions & 3 deletions dist/chains/cosmos/methods.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { type StdFee } from '@cosmjs/stargate';
import { type TX_MSG_TYPE } from './types';
export declare const cosmosTransfer: ({ sourceChannel, sourceAddress, destAddress, amount, assetId, fee, chainId, rpc, memo, timeout, txMsg }: {
import { Keplr } from '@keplr-wallet/types';
export declare const cosmosTransfer: ({ sourceChannel, sourceAddress, destAddress, amount, assetId, fee, chainId, rpc, memo, timeout, txMsg, keplr, gasPrice, gas, feeAssetId, }: {
sourceChannel: number;
sourceAddress: string;
destAddress: string;
amount: string;
assetId: string;
fee: "auto" | StdFee;
fee: string;
chainId: string;
rpc: string;
memo: string;
timeout?: number;
txMsg?: TX_MSG_TYPE;
keplr: Keplr;
gasPrice: string;
gas: string;
feeAssetId: string;
}) => Promise<string>;
//# sourceMappingURL=methods.d.ts.map
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.

Loading

0 comments on commit d985b83

Please sign in to comment.