-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-sol-tbtc
- Loading branch information
Showing
102 changed files
with
2,604 additions
and
3,811 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* | ||
!.gitignore | ||
!package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"version": "0.1.0-autogenerated.1636418960291530843", | ||
"name": "@polkadot-api/descriptors", | ||
"files": [ | ||
"dist" | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"module": "./dist/index.mjs", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"browser": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"sideEffects": false, | ||
"peerDependencies": { | ||
"polkadot-api": "*" | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": 0, | ||
"descriptorPath": ".papi/descriptors", | ||
"entries": { | ||
"assethub": { | ||
"wsUrl": "wss://polkadot-asset-hub-rpc.polkadot.io", | ||
"metadata": ".papi/metadata/assethub.scale" | ||
}, | ||
"hydration": { | ||
"wsUrl": "wss://hydradx-rpc.dwellir.com", | ||
"metadata": ".papi/metadata/hydration.scale" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * as evm from './evm'; | ||
export * as solana from './solana'; | ||
export * as substrate from './substrate'; | ||
export * as substrateV2 from './substrateV2'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Binary, TxEvent } from 'polkadot-api'; | ||
|
||
import { assethub } from '@polkadot-api/descriptors'; | ||
|
||
import type { AnyChain, AnyParachain } from '@galacticcouncil/xcm-core'; | ||
import type { Call, SubstrateCall } from '@galacticcouncil/xcm-sdk'; | ||
|
||
import { getSignerBySource, getWs, getFeeAsset } from './v2'; | ||
|
||
export async function signAndSend( | ||
address: string, | ||
call: Call, | ||
chain: AnyChain, | ||
observer: (value: TxEvent) => void | ||
) { | ||
const ctx = chain as AnyParachain; | ||
const signer = await getSignerBySource('polkadot-js', address); | ||
|
||
const { data, txOptions } = call as SubstrateCall; | ||
|
||
const apiPjs = await ctx.api; | ||
const extrinsic = apiPjs.tx(data); | ||
|
||
const client = await getWs(ctx.ws); | ||
const api = client.getTypedApi(assethub); | ||
|
||
const callData = Binary.fromHex(extrinsic.inner.toHex()); | ||
|
||
let opts = {}; | ||
if (txOptions && txOptions.asset) { | ||
const feeAsset = getFeeAsset(ctx, txOptions.asset); | ||
opts = { | ||
...opts, | ||
asset: feeAsset, | ||
}; | ||
} | ||
|
||
const tx = await api.txFromCallData(callData); | ||
tx.signSubmitAndWatch(signer, opts).subscribe(observer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { PolkadotSigner } from 'polkadot-api'; | ||
|
||
import { | ||
getInjectedExtensions, | ||
connectInjectedExtension, | ||
InjectedExtension, | ||
InjectedPolkadotAccount, | ||
} from 'polkadot-api/pjs-signer'; | ||
|
||
export const getSignerBySource = async ( | ||
source: string, | ||
address: string | ||
): Promise<PolkadotSigner> => { | ||
const extensions: string[] = getInjectedExtensions(); | ||
const extension = extensions.find((e) => e === source); | ||
|
||
if (!extension) { | ||
throw new Error('No wallet extension forund for ' + source); | ||
} | ||
|
||
const selectedExtension: InjectedExtension = | ||
await connectInjectedExtension(extension); | ||
|
||
const accounts: InjectedPolkadotAccount[] = selectedExtension.getAccounts(); | ||
const account = accounts.find((a) => a.address === address); | ||
|
||
if (!account) { | ||
throw new Error('Account is not connected: ' + address); | ||
} | ||
return account.polkadotSigner; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './extension'; | ||
export * from './provider'; | ||
export * from './utils'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createClient, PolkadotClient } from 'polkadot-api'; | ||
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat'; | ||
|
||
export const getWs = async ( | ||
wsUrl: string | string[] | ||
): Promise<PolkadotClient> => { | ||
const endpoints = typeof wsUrl === 'string' ? wsUrl.split(',') : wsUrl; | ||
const isNodeJs = typeof window === 'undefined'; | ||
const getWsProvider = isNodeJs | ||
? (await import('polkadot-api/ws-provider/node')).getWsProvider | ||
: (await import('polkadot-api/ws-provider/web')).getWsProvider; | ||
|
||
const wsProvider = getWsProvider(endpoints); | ||
return createClient(withPolkadotSdkCompat(wsProvider)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { XcmV3Junctions } from '@polkadot-api/descriptors'; | ||
|
||
export type XcmV3Multilocation = { | ||
parents: number; | ||
interior: XcmV3Junctions; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { XcmV3Junctions, XcmV3Junction } from '@polkadot-api/descriptors'; | ||
|
||
import { AnyParachain, Asset, multiloc } from '@galacticcouncil/xcm-core'; | ||
|
||
import { XcmV3Multilocation } from './types'; | ||
|
||
export const getFeeAsset = (chain: AnyParachain, asset: Asset) => { | ||
const location = chain.getAssetXcmLocation(asset); | ||
if (location) { | ||
const pallet = multiloc.findPalletInstance(location); | ||
const index = multiloc.findGeneralIndex(location); | ||
|
||
return { | ||
parents: 0, | ||
interior: XcmV3Junctions.X2([ | ||
XcmV3Junction.PalletInstance(Number(pallet)), | ||
XcmV3Junction.GeneralIndex(BigInt(index)), | ||
]), | ||
} as XcmV3Multilocation; | ||
} | ||
throw new Error('Asset locations not found'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.