Skip to content

Commit

Permalink
fix: lib updates for webapp abstractions (#162)
Browse files Browse the repository at this point in the history
Co-authored-by: Jesse <eitjuh@gmail.com>
  • Loading branch information
clockworkgr and eitjuh authored Apr 8, 2022
1 parent e836ed8 commit d0d40c8
Show file tree
Hide file tree
Showing 10 changed files with 2,800 additions and 2,820 deletions.
7 changes: 3 additions & 4 deletions packages/chain-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@emeris/chain-config",
"version": "0.0.7",
"version": "0.0.11",
"description": "Emeris chain config api Library",
"author": "Tendermint, Inc <hello@tendermint.com>",
"homepage": "https://github.com/emerishq/emeris-libraries#readme",
Expand All @@ -26,12 +26,11 @@
"access": "public"
},
"devDependencies": {
"@emeris/types": "^0.0.31",
"@emeris/types": "^0.0.33",
"@types/node": "^17.0.23",
"typescript": "^4.6.3"
},
"dependencies": {
"@vespaiach/axios-fetch-adapter": "^0.2.0",
"axios": "^0.21.1"
"isomorphic-fetch": "^3.0.0"
}
}
33 changes: 19 additions & 14 deletions packages/chain-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { EmerisAPI, EmerisBase } from "@emeris/types";
import axios from 'axios';
// @ts-ignore
import adapter from '@vespaiach/axios-fetch-adapter';
import { AxiosResponse } from 'axios';
import 'isomorphic-fetch';


export default class ChainConfig {
private endpoint:string;
Expand All @@ -11,17 +9,17 @@ export default class ChainConfig {
}
async getChains(): Promise<EmerisAPI.Chain[]> {
try {
const chainsResult:AxiosResponse<EmerisAPI.ChainsResponse> = await axios.get(this.endpoint+'/chains', { adapter });
const chains = await Promise.all(chainsResult.data.chains.map(async (chain) => await this.getChain(chain.chain_name)));
const chainsResult:EmerisAPI.ChainsResponse = (await (await fetch(this.endpoint+'/chains')).json());
const chains = await Promise.all(chainsResult.chains.map(async (chain) => await this.getChain(chain.chain_name)));
return chains;
}catch(e) {
throw new Error("Could not get chains information: "+ e);
}
}
async getChain(chain_name:string):Promise<EmerisAPI.Chain> {
try {
const result:AxiosResponse<EmerisAPI.ChainResponse> = await axios.get(this.endpoint+'/chain/'+chain_name, { adapter });
return result.data?.chain ?? null;
const result:EmerisAPI.ChainResponse = (await (await fetch(this.endpoint+'/chain/'+chain_name)).json());
return result.chain ?? null;
}catch(e) {
throw new Error("Could not get chain information: "+ e);
}
Expand Down Expand Up @@ -60,18 +58,25 @@ export default class ChainConfig {
}
async getNumbers(chain_name:string, key_hash: string): Promise<EmerisAPI.SeqNumber> {
try {
const result: AxiosResponse<{ numbers: EmerisAPI.SeqNumber }> = await axios.get(
this.endpoint+ '/chain/' + chain_name + '/numbers/' + key_hash, { adapter }
)
return result.data?.numbers ?? null
const result:{ numbers: EmerisAPI.SeqNumber } = (await (await fetch(
this.endpoint+ '/chain/' + chain_name + '/numbers/' + key_hash)).json());
return result.numbers ?? null
} catch (e) {
throw new Error('Could not get account numbers' + e);
}
}
async getFee(tx: Uint8Array, chain_name: string): Promise<unknown> {
try {
const result: AxiosResponse<unknown> = await axios.post(this.endpoint+ '/tx/' + chain_name + '/simulate', { tx_bytes: Buffer.from(tx).toString('base64') }, { adapter });
return result.data ?? null;
const result:unknown = (await (await fetch(this.endpoint+ '/tx/' + chain_name + '/simulate',
{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({ tx_bytes: Buffer.from(tx).toString('base64') })
})).json());
return result ?? null;
} catch (e) {
throw "Could not get account numbers";
}
Expand Down
7 changes: 4 additions & 3 deletions packages/emeris-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"@cosmjs/stream": "0.28.0",
"@cosmjs/tendermint-rpc": "0.28.0",
"@cosmjs/utils": "0.28.0",
"@emeris/chain-config": "^0.0.7",
"@emeris/mapper": "^0.0.15",
"@emeris/chain-config": "^0.0.11",
"@emeris/mapper": "^0.0.26",
"@emeris/signer": "^0.0.27",
"@ledgerhq/hw-transport-webhid": "^6.11.2",
"@ledgerhq/hw-transport-webusb": "^6.11.2",
Expand Down Expand Up @@ -81,7 +81,8 @@
"xstate": "^4.30.6"
},
"devDependencies": {
"@emeris/types": "^0.0.27",
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
"@emeris/types": "^0.0.33",
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
"@intlify/vite-plugin-vue-i18n": "^3.3.1",
Expand Down
55 changes: 50 additions & 5 deletions packages/emeris-extension/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,13 @@
enabled "2.0.x"
kuler "^2.0.0"

"@emeris/chain-config@^0.0.11":
version "0.0.11"
resolved "https://registry.yarnpkg.com/@emeris/chain-config/-/chain-config-0.0.11.tgz#1a9ac1e2f050fa0ff2596d4ba3532766642394ad"
integrity sha512-IL0sS2WB5tOlDmr5gJ/m2p2EL57LK83MeMRQ1TqnMsB7kRG7QU/Cls13+fmSoOl7R6ZjvILdFjjuda+FJMNmhw==
dependencies:
isomorphic-fetch "^3.0.0"

"@emeris/chain-config@^0.0.7":
version "0.0.7"
resolved "https://registry.yarnpkg.com/@emeris/chain-config/-/chain-config-0.0.7.tgz#830c3c3e706397fb3ce424ca942c783c9fef758c"
Expand All @@ -1112,15 +1119,15 @@
"@vespaiach/axios-fetch-adapter" "^0.2.0"
axios "^0.21.1"

"@emeris/mapper@^0.0.15":
version "0.0.15"
resolved "https://registry.yarnpkg.com/@emeris/mapper/-/mapper-0.0.15.tgz#cc34b3026e415846459b9a083868d41f8880b427"
integrity sha512-dwDvGcVv3HnAuX8stZ8RIrj8OJFjSUplx9i/JAp/KSglMXExw6vXyBGYTY5XnEHISQSugB5LhHXweGNXC9Lkqg==
"@emeris/mapper@^0.0.23":
version "0.0.23"
resolved "https://registry.yarnpkg.com/@emeris/mapper/-/mapper-0.0.23.tgz#749227253ebf14c107144c99a8a28bd49be0c33f"
integrity sha512-/ozHa9EJqVw3DJT5tTWiIj6lWhm33/c3WaI8VXfaapEgK+TzAhFedMgfZpuWVVPkgTp9AFWEpL9llUI7iNlaXQ==
dependencies:
"@clockwork-projects/cosmos-gaia-js" "^6.0.0"
"@clockwork-projects/osmosis-labs-osmosis-js" "^6.1.0"
"@cosmjs/amino" "^0.28.0"
"@emeris/chain-config" "^0.0.7"
"@emeris/chain-config" "^0.0.11"
bignumber.js "^9.0.2"
protobufjs "^6.11.2"

Expand Down Expand Up @@ -4235,6 +4242,14 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=

isomorphic-fetch@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz#0267b005049046d2421207215d45d6a262b8b8b4"
integrity sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==
dependencies:
node-fetch "^2.6.1"
whatwg-fetch "^3.4.1"

isomorphic-ws@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-4.0.1.tgz#55fd4cd6c5e6491e76dc125938dd863f5cd4f2dc"
Expand Down Expand Up @@ -4825,6 +4840,13 @@ node-addon-api@^2.0.0:
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32"
integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==

node-fetch@^2.6.1:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
dependencies:
whatwg-url "^5.0.0"

node-gyp-build@^4.2.0, node-gyp-build@^4.3.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.4.0.tgz#42e99687ce87ddeaf3a10b99dc06abc11021f3f4"
Expand Down Expand Up @@ -6043,6 +6065,11 @@ tr46@^3.0.0:
dependencies:
punycode "^2.1.1"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=

triple-beam@1.3.0, triple-beam@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.3.0.tgz#a595214c7298db8339eeeee083e4d10bd8cb8dd9"
Expand Down Expand Up @@ -6373,6 +6400,11 @@ webextension-polyfill@^0.9.0:
resolved "https://registry.yarnpkg.com/webextension-polyfill/-/webextension-polyfill-0.9.0.tgz#de6c1941d0ef1b0858b20e9c7b46bbc042c5a960"
integrity sha512-LTtHb0yR49xa9irkstDxba4GATDAcDw3ncnFH9RImoFwDlW47U95ME5sn5IiQX2ghfaECaf6xyXM8yvClIBkkw==

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=

webidl-conversions@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-7.0.0.tgz#256b4e1882be7debbf01d05f0aa2039778ea080a"
Expand All @@ -6385,6 +6417,11 @@ whatwg-encoding@^2.0.0:
dependencies:
iconv-lite "0.6.3"

whatwg-fetch@^3.4.1:
version "3.6.2"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz#dced24f37f2624ed0281725d51d0e2e3fe677f8c"
integrity sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==

whatwg-mimetype@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz#5fa1a7623867ff1af6ca3dc72ad6b8a4208beba7"
Expand All @@ -6398,6 +6435,14 @@ whatwg-url@^10.0.0:
tr46 "^3.0.0"
webidl-conversions "^7.0.0"

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

which-module@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"
Expand Down
6 changes: 3 additions & 3 deletions packages/mapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@emeris/mapper",
"version": "0.0.15",
"version": "0.0.26",
"description": "Emeris Tx-mapping Library",
"author": "Tendermint, Inc <hello@tendermint.com>",
"homepage": "https://github.com/allinbits/emeris-libraries#readme",
Expand All @@ -26,7 +26,7 @@
"access": "public"
},
"devDependencies": {
"@emeris/types": "^0.0.31",
"@emeris/types": "^0.0.33",
"@types/long": "^4.0.1",
"long": "^4.0.0",
"typescript": "^4.4.4"
Expand All @@ -35,7 +35,7 @@
"@clockwork-projects/cosmos-gaia-js": "^6.0.0",
"@clockwork-projects/osmosis-labs-osmosis-js": "^6.1.0",
"@cosmjs/amino": "^0.28.0",
"@emeris/chain-config": "^0.0.7",
"@emeris/chain-config": "^0.0.11",
"bignumber.js": "^9.0.2",
"protobufjs": "^6.11.2"
}
Expand Down
7 changes: 3 additions & 4 deletions packages/mapper/src/implementations/cosmos/gravity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default class GravityAminoMessageMapper extends CosmosAminoMessageMapper
swap(transaction: EmerisTransactions.AbstractSwapTransactionData, signing_address: string) {
const pool = transaction.pool as unknown as Pool;
const offerCoinFee = (new BigNumber(transaction.from.amount)).multipliedBy(0.0015)
BigNumber.set({ DECIMAL_PLACES: 0 });
const price = [transaction.from, transaction.to].sort((a, b) => {
if (a.denom < b.denom) return -1;
if (a.denom > b.denom) return 1;
Expand All @@ -18,11 +17,11 @@ export default class GravityAminoMessageMapper extends CosmosAminoMessageMapper
type: "liquidity/MsgSwapWithinBatch",
value: {
swap_requester_address: signing_address,
pool_id: pool.id,
swap_type_id: pool.typeId,
pool_id: parseInt(pool.id as unknown as string),
swap_type_id: (pool as any).type_id,
offer_coin: transaction.from,
demand_coin_denom: transaction.to.denom,
offer_coin_fee: {amount: offerCoinFee.toString(), denom: transaction.from.denom },
offer_coin_fee: {amount: offerCoinFee.integerValue(BigNumber.ROUND_CEIL).toString(), denom: transaction.from.denom },
order_price: (new BigNumber(price[0].amount)).dividedBy( new BigNumber(price[1].amount)).toString()
}
}
Expand Down
14 changes: 7 additions & 7 deletions packages/mapper/src/implementations/cosmos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export default class CosmosAminoMessageMapper extends EmerisMessageMapper {
return {
type: "cosmos-sdk/MsgSend",
value: {
amount: [this.normalizeAmount(transaction.amount)],
from_address: signing_address,
// @ts-ignore
to_address: transaction.toAddress,
from_address: signing_address,
amount: [this.normalizeAmount(transaction.amount)],
},
};
}
Expand All @@ -25,8 +25,8 @@ export default class CosmosAminoMessageMapper extends EmerisMessageMapper {
sender: signing_address,
// @ts-ignore
receiver: transaction.toAddress,
timeout_timestamp: Long.fromString(new Date().getTime() + 300000 + '000000'),
//timeoutHeight: { revisionHeight: "10000000000",revisionNumber:"0"},
timeout_timestamp: new Date().getTime() + 300000 + '000000',
timeoutHeight: {},
token: this.normalizeAmount(transaction.amount),
}
}
Expand All @@ -40,8 +40,8 @@ export default class CosmosAminoMessageMapper extends EmerisMessageMapper {
sender: signing_address,
// @ts-ignore
receiver: transaction.toAddress,
timeout_timestamp: Long.fromString(new Date().getTime() + 300000 + '000000'),
//timeoutHeight: { revisionHeight: "10000000000",revisionNumber:"0"},
timeout_timestamp: new Date().getTime() + 300000 + '000000',
timeoutHeight: {},
token: this.normalizeAmount(transaction.amount),
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ export default class CosmosAminoMessageMapper extends EmerisMessageMapper {
}
claim(transaction: EmerisTransactions.AbstractClaimRewardsTransactionData, signing_address: string) {
return transaction.rewards.map((transaction) => ({
type: "cosmos-sdk/MsgWithdrawDelegatorReward",
type: "cosmos-sdk/MsgWithdrawDelegationReward",
value: {
delegator_address: signing_address,
validator_address: transaction.validator_address
Expand Down
4 changes: 2 additions & 2 deletions packages/signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.15.0",
"@emeris/types": "0.0.31",
"@emeris/types": "0.0.33",
"@types/node": "^16.11.26",
"@types/reconnectingwebsocket": "^1.0.7",
"@types/w3c-web-usb": "^1.0.6",
Expand All @@ -52,7 +52,7 @@
"@cosmjs/ledger-amino": "^0.28.0",
"@cosmjs/proto-signing": "^0.28.0",
"@cosmjs/stargate": "^0.28.0",
"@emeris/chain-config": "^0.0.7",
"@emeris/chain-config": "^0.0.11",
"@ledgerhq/hw-transport-webusb": "^6.20.0",
"@starport/vuex": "^0.1.58",
"@terra-money/terra.js": "^1.8.10",
Expand Down
Loading

0 comments on commit d0d40c8

Please sign in to comment.