Skip to content

Commit

Permalink
Peter/fix q token vaults support (#1445)
Browse files Browse the repository at this point in the history
* chore: update monetary to latest 0.7.3

* wip

* wip: update lib version

* chore: install deps
  • Loading branch information
peterslany authored Jul 11, 2023
1 parent 9c16ae5 commit a96dab8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 70 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@headlessui/react": "^1.1.1",
"@heroicons/react": "^2.0.18",
"@interlay/bridge": "^0.3.13",
"@interlay/interbtc-api": "2.3.5",
"@interlay/interbtc-api": "2.3.6",
"@interlay/monetary-js": "0.7.3",
"@polkadot/api": "9.14.2",
"@polkadot/extension-dapp": "0.44.1",
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Vaults/Vault/VaultIssueRequestsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const VaultIssueRequestsTable = ({ vaultAddress, collateralToken }: Props): JSX.
} = useQuery<GraphqlReturn<any>, Error>(
[
GRAPHQL_FETCHER,
issuesCountQuery(`vault: {accountId_eq: "${vaultAddress}", collateralToken: {${collateralTokenCondition}}}`) // TODO: add condition for asset_eq when the page is refactored for accepting ForeignAsset currencies too (cf. e.g. issued graph in dashboard for example)
issuesCountQuery(`vault: {accountId_eq: "${vaultAddress}", collateralToken: {${collateralTokenCondition}}}`)
],
graphqlFetcher<GraphqlReturn<any>>()
);
Expand All @@ -72,7 +72,7 @@ const VaultIssueRequestsTable = ({ vaultAddress, collateralToken }: Props): JSX.
} = useIssueRequests(
selectedPageIndex * TABLE_PAGE_LIMIT,
TABLE_PAGE_LIMIT,
`vault: {accountId_eq: "${vaultAddress}", collateralToken: {${collateralTokenCondition}}}`, // `WHERE` condition // TODO: add asset_eq, see comment above
`vault: {accountId_eq: "${vaultAddress}", collateralToken: {${collateralTokenCondition}}}`, // `WHERE` condition
ISSUE_REDEEM_REQUEST_REFETCH_INTERVAL
);
useErrorHandler(issueRequestsError);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Vaults/Vault/VaultRedeemRequestsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const VaultRedeemRequestsTable = ({ vaultAddress, collateralToken }: Props): JSX
} = useQuery<GraphqlReturn<any>, Error>(
[
GRAPHQL_FETCHER,
redeemCountQuery(`vault: {accountId_eq: "${vaultAddress}", collateralToken: {${collateralTokenCondition}}}`) // TODO: add condition for asset_eq when the page is refactored for accepting ForeignAsset currencies too (cf. e.g. issued graph in dashboard for example)
redeemCountQuery(`vault: {accountId_eq: "${vaultAddress}", collateralToken: {${collateralTokenCondition}}}`)
],
graphqlFetcher<GraphqlReturn<any>>()
);
Expand All @@ -102,7 +102,7 @@ const VaultRedeemRequestsTable = ({ vaultAddress, collateralToken }: Props): JSX
REDEEMS_FETCHER,
selectedPageIndex * TABLE_PAGE_LIMIT, // offset
TABLE_PAGE_LIMIT, // limit
`vault: {accountId_eq: "${vaultAddress}", collateralToken: {${collateralTokenCondition}}}` // `WHERE` condition // TODO: add asset_eq, see comment above
`vault: {accountId_eq: "${vaultAddress}", collateralToken: {${collateralTokenCondition}}}` // `WHERE` condition
],
redeemsFetcher,
{
Expand Down
15 changes: 11 additions & 4 deletions src/utils/helpers/currencies.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { CurrencyExt } from '@interlay/interbtc-api';
import { CurrencyExt, isForeignAsset, isLendToken } from '@interlay/interbtc-api';
import { MonetaryAmount } from '@interlay/monetary-js';

// Squid query by currency ticker for native assets and by id for foreign assets.
// We need to differentiate because those are handled differently on squid side.
// TODO: Need to refactor when we want to support lend tokens as collateral for vaults.
const getCurrencyEqualityCondition = (currency: CurrencyExt): string =>
'foreignAsset' in currency ? `asset_eq: ${currency.foreignAsset.id}` : `token_eq: ${currency.ticker}`;

const getCurrencyEqualityCondition = (currency: CurrencyExt): string => {
if (isForeignAsset(currency)) {
return `asset_eq: ${currency.foreignAsset.id}`;
}
if (isLendToken(currency)) {
return `lendTokenId_eq: ${currency.lendToken.id}`;
}
return `token_eq: ${currency.ticker}`;
};

const pickSmallerAmount = (
amount0: MonetaryAmount<CurrencyExt>,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/hooks/api/vaults/get-vault-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const getVaultData = async (vault: VaultExt, accountId: AccountId, prices: Price
},
body: JSON.stringify({
query: redeemCountQuery(
`vault: {accountId_eq: "${formattedAccountId}", collateralToken: {${collateralTokenCondition}}}, status_eq: Pending` // TODO: add asset_eq, see comment above
`vault: {accountId_eq: "${formattedAccountId}", collateralToken: {${collateralTokenCondition}}}, status_eq: Pending`
)
})
});
Expand Down
65 changes: 5 additions & 60 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2125,16 +2125,15 @@
dependencies:
axios "^0.21.1"

"@interlay/[email protected].5":
version "2.3.5"
resolved "https://registry.yarnpkg.com/@interlay/interbtc-api/-/interbtc-api-2.3.5.tgz#d73c57e04391f9c300ca361cb9e0f2226c867b9c"
integrity sha512-sCaV+aI2oyQnP03PBBad/wqYMuZ3GlaDDrkbkr+LGshHgxwB42pvEeEehaEiXh0qsym6ZeH2FU6T++FP9PGlnQ==
"@interlay/[email protected].6":
version "2.3.6"
resolved "https://registry.yarnpkg.com/@interlay/interbtc-api/-/interbtc-api-2.3.6.tgz#2db11e94b495139da87d1052cdde39a7a8dd25ab"
integrity sha512-bfrDE7QqmG25NLeBpVvZb4tKp1Zr2DqG+lWZnU5L27Z0V/zzPdWDbBcBcG1uKEDy4lkxX8K9jYculy/UA/rW1g==
dependencies:
"@interlay/esplora-btc-api" "0.4.0"
"@interlay/interbtc-types" "1.12.0"
"@interlay/monetary-js" "0.7.3"
"@polkadot/api" "9.14.2"
"@types/bitcoinjs-lib" "^5.0.0"
big.js "6.1.1"
bitcoin-core "^3.0.0"
bitcoinjs-lib "^5.2.0"
Expand Down Expand Up @@ -2571,11 +2570,6 @@
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.2.0.tgz#a3150eeb09cc7ab207ebf6d7b9ad311a9bdbed12"
integrity sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==

"@noble/hashes@^1.2.0":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9"
integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==

"@noble/[email protected]":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.1.tgz#b251c70f824ce3ca7f8dc3df08d58f005cc0507c"
Expand Down Expand Up @@ -6006,13 +6000,6 @@
resolved "https://registry.yarnpkg.com/@types/big.js/-/big.js-6.1.2.tgz#68a952b629a6aaa2b5855a2f63363d1e77f6dd91"
integrity sha512-h24JIZ52rvSvi2jkpYDk2yLH99VzZoCJiSfDWwjst7TwJVuXN61XVCUlPCzRl7mxKEMsGf8z42Q+J4TZwU3z2w==

"@types/bitcoinjs-lib@^5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@types/bitcoinjs-lib/-/bitcoinjs-lib-5.0.0.tgz#f2905d673d1c4b42a91d64d95f1c464f1a48cb56"
integrity sha512-9zXjgmH2E8qEZ9gQ9GH+I6Cze3bweQbyXtR/X4RD3SdR5I4jdRPvmBrKmjegV3HZG03KNricjEoq+lQUtIXCKQ==
dependencies:
bitcoinjs-lib "*"

"@types/bn.js@^5.1.1":
version "5.1.1"
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.1.tgz#b51e1b55920a4ca26e9285ff79936bbdec910682"
Expand Down Expand Up @@ -7736,11 +7723,6 @@ base-x@^3.0.2:
dependencies:
safe-buffer "^5.0.1"

base-x@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/base-x/-/base-x-4.0.0.tgz#d0e3b7753450c73f8ad2389b5c018a4af7b2224a"
integrity sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==

base64-js@^1.0.2, base64-js@^1.3.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
Expand Down Expand Up @@ -7776,11 +7758,6 @@ [email protected], bech32@^1.1.2:
resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9"
integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==

bech32@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/bech32/-/bech32-2.0.0.tgz#078d3686535075c8c79709f054b1b226a133b355"
integrity sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==

before-after-hook@^2.2.0:
version "2.2.3"
resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-2.2.3.tgz#c51e809c81a4e354084422b9b26bad88249c517c"
Expand Down Expand Up @@ -7850,11 +7827,6 @@ bip174@^2.0.1:
resolved "https://registry.yarnpkg.com/bip174/-/bip174-2.0.1.tgz#39cf8ca99e50ce538fb762589832f4481d07c254"
integrity sha512-i3X26uKJOkDTAalYAp0Er+qGMDhrbbh2o93/xiPyAN2s25KrClSpe3VXo/7mNJoqA5qfko8rLS2l3RWZgYmjKQ==

bip174@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/bip174/-/bip174-2.1.0.tgz#cd3402581feaa5116f0f00a0eaee87a5843a2d30"
integrity sha512-lkc0XyiX9E9KiVAS1ZiOqK1xfiwvf4FXDDdkDq5crcDzOq+xGytY+14qCsqz7kCiy8rpN1CRNfacRhf9G3JNSA==

bip32@^2.0.4:
version "2.0.6"
resolved "https://registry.yarnpkg.com/bip32/-/bip32-2.0.6.tgz#6a81d9f98c4cd57d05150c60d8f9e75121635134"
Expand Down Expand Up @@ -7893,18 +7865,6 @@ bitcoin-ops@^1.3.0, bitcoin-ops@^1.4.0:
resolved "https://registry.yarnpkg.com/bitcoin-ops/-/bitcoin-ops-1.4.1.tgz#e45de620398e22fd4ca6023de43974ff42240278"
integrity sha512-pef6gxZFztEhaE9RY9HmWVmiIHqCb2OyS4HPKkpc6CIiiOa3Qmuoylxc5P2EkU3w+5eTSifI9SEZC88idAIGow==

bitcoinjs-lib@*:
version "6.1.1"
resolved "https://registry.yarnpkg.com/bitcoinjs-lib/-/bitcoinjs-lib-6.1.1.tgz#3950c29fd96f07131e41a36a265b17ebd02b4a11"
integrity sha512-FYihfgTk29lt1eK2y48OtuarEDUnTprNBW3ctT8yHiOhvmeS3DzAVG6gI0VCvMkydz6UdlXlYNWIPqGD0SUYRQ==
dependencies:
"@noble/hashes" "^1.2.0"
bech32 "^2.0.0"
bip174 "^2.1.0"
bs58check "^3.0.1"
typeforce "^1.11.3"
varuint-bitcoin "^1.1.2"

bitcoinjs-lib@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/bitcoinjs-lib/-/bitcoinjs-lib-5.2.0.tgz#caf8b5efb04274ded1b67e0706960b93afb9d332"
Expand Down Expand Up @@ -8157,13 +8117,6 @@ bs58@^4.0.0:
dependencies:
base-x "^3.0.2"

bs58@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/bs58/-/bs58-5.0.0.tgz#865575b4d13c09ea2a84622df6c8cbeb54ffc279"
integrity sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ==
dependencies:
base-x "^4.0.0"

bs58check@<3.0.0, bs58check@^2.0.0, bs58check@^2.1.1, bs58check@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-2.1.2.tgz#53b018291228d82a5aa08e7d796fdafda54aebfc"
Expand All @@ -8173,14 +8126,6 @@ bs58check@<3.0.0, bs58check@^2.0.0, bs58check@^2.1.1, bs58check@^2.1.2:
create-hash "^1.1.0"
safe-buffer "^5.1.2"

bs58check@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-3.0.1.tgz#2094d13720a28593de1cba1d8c4e48602fdd841c"
integrity sha512-hjuuJvoWEybo7Hn/0xOrczQKKEKD63WguEjlhLExYs2wUBcebDC1jDNK17eEAD2lYfw82d5ASC1d7K3SWszjaQ==
dependencies:
"@noble/hashes" "^1.2.0"
bs58 "^5.0.0"

[email protected]:
version "2.1.1"
resolved "https://registry.yarnpkg.com/bser/-/bser-2.1.1.tgz#e6787da20ece9d07998533cfd9de6f5c38f4bc05"
Expand Down Expand Up @@ -20678,7 +20623,7 @@ value-equal@^1.0.1:
resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-1.0.1.tgz#1e0b794c734c5c0cade179c437d356d931a34d6c"
integrity sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==

varuint-bitcoin@^1.0.4, varuint-bitcoin@^1.1.2:
varuint-bitcoin@^1.0.4:
version "1.1.2"
resolved "https://registry.yarnpkg.com/varuint-bitcoin/-/varuint-bitcoin-1.1.2.tgz#e76c138249d06138b480d4c5b40ef53693e24e92"
integrity sha512-4EVb+w4rx+YfVM32HQX42AbbT7/1f5zwAYhIujKXKk8NQK+JfRVl3pqT3hjNn/L+RstigmGGKVwHA/P0wgITZw==
Expand Down

2 comments on commit a96dab8

@vercel
Copy link

@vercel vercel bot commented on a96dab8 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on a96dab8 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.