-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from nabla-studio/DavideSegullo/feat-signing
Davide segullo/feat signing
- Loading branch information
Showing
45 changed files
with
1,209 additions
and
96 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
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,22 @@ | ||
'use client'; | ||
|
||
import { useChain, useConnect } from '@quirks/react'; | ||
|
||
export const TestChain = () => { | ||
const { connected } = useConnect(); | ||
const { address, chain } = useChain('osmosis'); | ||
|
||
if (!connected) { | ||
return false; | ||
} | ||
|
||
return ( | ||
<div> | ||
<div>Chain ID: {chain.chain_id}</div> | ||
|
||
<div>Chain Name: Osmosis</div> | ||
|
||
<div>Address: {address}</div> | ||
</div> | ||
); | ||
}; |
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,7 @@ | ||
# Noop | ||
|
||
This is copied as a design pattern from Keplr-wallet! | ||
|
||
https://github.com/chainapsis/keplr-wallet/tree/v0.12.25/etc/noop | ||
|
||
> This directory isn’t actually used, and would be preferred to not be added. But it is needed to explicitly ignore specific libraries used by the dependency. Specifically, libsodium isn’t actually used and WebAssembly can’t be used in the extension’s sandbox environment but creates various errors so the directory exists to ignore libsodium. |
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 @@ | ||
module.exports = {}; |
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,8 @@ | ||
{ | ||
"name": "noop", | ||
"version": "0.0.1", | ||
"main": "index.js", | ||
"private": true, | ||
"scripts": {}, | ||
"dependencies": {} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { EncodeObject } from '@cosmjs/proto-signing'; | ||
|
||
export interface SigningSimulatorClient { | ||
simulate( | ||
signerAddress: string, | ||
messages: readonly EncodeObject[], | ||
memo: string | undefined, | ||
): Promise<number>; | ||
} |
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,18 @@ | ||
import { Chain } from '@nabla-studio/chain-registry'; | ||
import { assertIsDefined } from './asserts'; | ||
|
||
export const getEndpoint = (chainName: string, chains: Chain[]) => { | ||
const chain = chains.find((el) => el.chain_name === chainName); | ||
|
||
assertIsDefined(chain); | ||
assertIsDefined(chain.apis?.rpc); | ||
assertIsDefined(chain.apis?.rest); | ||
|
||
const rpc = chain.apis.rpc[0]; | ||
const rest = chain.apis.rest[0]; | ||
|
||
return { | ||
rpc, | ||
rest, | ||
}; | ||
}; |
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,57 @@ | ||
import type { EncodeObject } from '@cosmjs/proto-signing'; | ||
import { calculateFee, GasPrice } from '@cosmjs/stargate'; | ||
import { assertIsDefined } from './asserts'; | ||
import type { SigningSimulatorClient } from '../types'; | ||
import type { Chain } from '@nabla-studio/chain-registry'; | ||
|
||
/** | ||
* Retrieve chain gas price so we can use fee auto. | ||
* | ||
* @param chain | ||
* @param feeDenom ex. uosmo | ||
* @returns | ||
*/ | ||
export const getGasPrice = (chain: Chain, feeDenom?: string) => { | ||
let gasPrice: GasPrice | undefined = undefined; | ||
|
||
if (chain.fees && chain.fees.fee_tokens.length > 0) { | ||
let feeToken = undefined; | ||
|
||
if (feeToken) { | ||
feeToken = chain.fees.fee_tokens.find( | ||
(token) => token.denom === feeDenom, | ||
); | ||
} else { | ||
chain.fees.fee_tokens[0]; | ||
} | ||
|
||
const averageGasPrice = feeToken?.average_gas_price; | ||
const denom = feeToken?.denom; | ||
|
||
if (averageGasPrice && denom && !denom.startsWith('ibc/')) { | ||
gasPrice = GasPrice.fromString(`${averageGasPrice}${denom}`); | ||
} else { | ||
gasPrice = GasPrice.fromString(`1${denom}`); | ||
} | ||
} | ||
|
||
return gasPrice; | ||
}; | ||
|
||
export const estimateFee = async ( | ||
client: SigningSimulatorClient, | ||
sender: string, | ||
messages: EncodeObject[], | ||
gasPrice?: string | GasPrice, | ||
memo?: string, | ||
multiplier = 1.4, | ||
) => { | ||
assertIsDefined( | ||
gasPrice, | ||
'Gas price must be set in the client options when auto gas is used.', | ||
); | ||
|
||
const gasEstimation = await client.simulate(sender, messages, memo); | ||
|
||
return calculateFee(Math.round(gasEstimation * multiplier), gasPrice); | ||
}; |
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,5 @@ | ||
export * from './extension'; | ||
export * from './asserts'; | ||
export * from './errors'; | ||
export * from './fees'; | ||
export * from './endpoints'; |
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.