Compare commits

..
Author SHA1 Message Date
Bob van der Helm 06db4a2faa update health computer for perps (#823)
* update health computer for perps

* update health computer + fix comments
2024-02-23 13:57:27 +01:00
Linkie Link 5846e893d1 Merge branch 'main' of https://github.com/mars-protocol/mars-v2-frontend into develop 2024-02-16 09:07:22 +01:00
Linkie Link e3b5e330ee Merge branch 'main' of https://github.com/mars-protocol/mars-v2-frontend into develop
# Conflicts:
#	.env
#	src/components/perps/BalancesTable/index.tsx
2024-02-14 19:30:55 +01:00
Linkie LinkandBob van der Helm 7eac8e7a35 Update Dockerbuild (#813)
* v2.2.4 (#810)

* feat: handle URLs with or without trailing slash (#803)

* feat: handle URLs with or without trailing slash

* tidy: cleanup slashes

* Fix docker build (#805)

* fix: fixed the docker build

* tidy: cleanup

* env: remove env contents (#808)

* Portfolio fix (#809)

* fix: fixed the portfolio account detail page layout

* fix: fixed portfolio cards

* tidy: refactor

* align buttons, perps row clickable (#807)

* align buttons, perps row clickable

* fix comments

* update to v2.2.4

* fix borrowbutton logic, add vault deposit manage btn, fix icon size vault modal

---------

Co-authored-by: Linkie Link <linkielink.dev@gmail.com>

---------

Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com>

* Update Dockerfile

* remove   .env files

* tidy: format

---------

Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com>
2024-02-14 19:29:41 +01:00
Linkie Link af478c56d5 Update .env.production 2024-02-14 16:43:57 +01:00
Bob van der HelmandLinkie Link a6f4c24f15 align buttons, perps row clickable (#807)
* align buttons, perps row clickable

* fix comments

* update to v2.2.4

* fix borrowbutton logic, add vault deposit manage btn, fix icon size vault modal

---------

Co-authored-by: Linkie Link <linkielink.dev@gmail.com>
2024-02-14 14:49:15 +01:00
Linkie Link 6946ceddfc Portfolio fix (#809)
* fix: fixed the portfolio account detail page layout

* fix: fixed portfolio cards

* tidy: refactor
2024-02-14 14:18:10 +01:00
Linkie Link 0154065ffb env: remove env contents (#808) 2024-02-14 12:33:10 +01:00
Linkie Link 4f64234a75 Merge branch 'main' into develop 2024-02-14 12:01:10 +01:00
Linkie Link 26f1ef4a2c Fix docker build (#805)
* fix: fixed the docker build

* tidy: cleanup
2024-02-14 11:58:48 +01:00
Linkie Link 3f28ccd09c feat: handle URLs with or without trailing slash (#803)
* feat: handle URLs with or without trailing slash

* tidy: cleanup slashes
2024-02-14 09:26:10 +01:00
24 changed files with 501 additions and 568 deletions
-34
View File
@@ -1,34 +0,0 @@
name: Publish ApplicationRecord to Registry
on:
release:
types: [published]
push:
branches:
- publish-to-registry
env:
CERC_REGISTRY_USER_KEY: ${{ secrets.CICD_LACONIC_USER_KEY }}
CERC_REGISTRY_BOND_ID: ${{ secrets.CICD_LACONIC_BOND_ID }}
jobs:
cns_publish:
runs-on: ubuntu-latest
steps:
- name: "Clone project repository"
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: "Install Yarn"
run: npm install -g yarn
- name: "Install registry CLI"
run: |
npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/
yarn global add @cerc-io/laconic-registry-cli
- name: "Install jq"
run: apt -y update && apt -y install jq
- name: "Publish Application Record"
run: scripts/publish-app-record.sh
- name: "Request Deployment"
run: scripts/request-app-deployment.sh
-2
View File
@@ -1,7 +1,5 @@
# Mars Protocol v2 Outpost Frontend
ci
![mars-banner-1200w](https://marsprotocol.io/banner.png)
## 1. Web App
+1 -2
View File
@@ -1,6 +1,5 @@
{
"name": "@lx-mars/mars-v2-frontend",
"repository": "https://git.vdb.to/LaconicNetwork/mars-v2-frontend",
"name": "mars-v2-frontend",
"version": "2.2.4",
"homepage": "./",
"private": false,
-69
View File
@@ -1,69 +0,0 @@
#!/bin/bash
set -e
RECORD_FILE=tmp.rf.$$
CONFIG_FILE=`mktemp`
CERC_APP_TYPE=${CERC_APP_TYPE:-"webapp"}
CERC_REPO_REF=${CERC_REPO_REF:-${GITHUB_SHA:-`git log -1 --format="%H"`}}
CERC_IS_LATEST_RELEASE=${CERC_IS_LATEST_RELEASE:-"true"}
rcd_name=$(jq -r '.name' package.json | sed 's/null//')
rcd_desc=$(jq -r '.description' package.json | sed 's/null//')
rcd_repository=$(jq -r '.repository' package.json | sed 's/null//')
rcd_homepage=$(jq -r '.homepage' package.json | sed 's/null//')
rcd_license=$(jq -r '.license' package.json | sed 's/null//')
rcd_author=$(jq -r '.author' package.json | sed 's/null//')
rcd_app_version=$(jq -r '.version' package.json | sed 's/null//')
cat <<EOF > "$CONFIG_FILE"
services:
cns:
restEndpoint: '${CERC_REGISTRY_REST_ENDPOINT:-http://console.laconic.com:1317}'
gqlEndpoint: '${CERC_REGISTRY_GQL_ENDPOINT:-http://console.laconic.com:9473/api}'
chainId: ${CERC_REGISTRY_CHAIN_ID:-laconic_9000-1}
gas: 1750000
fees: 20000aphoton
EOF
next_ver=$(laconic -c $CONFIG_FILE cns record list --type ApplicationRecord --all --name "$rcd_name" 2>/dev/null | jq -r -s ".[] | sort_by(.createTime) | reverse | [ .[] | select(.bondId == \"$CERC_REGISTRY_BOND_ID\") ] | .[0].attributes.version" | awk -F. -v OFS=. '{$NF += 1 ; print}')
if [ -z "$next_ver" ] || [ "1" == "$next_ver" ]; then
next_ver=0.0.1
fi
cat <<EOF | sed '/.*: ""$/d' > "$RECORD_FILE"
record:
type: ApplicationRecord
version: ${next_ver}
name: "$rcd_name"
description: "$rcd_desc"
homepage: "$rcd_homepage"
license: "$rcd_license"
author: "$rcd_author"
repository:
- "$rcd_repository"
repository_ref: "$CERC_REPO_REF"
app_version: "$rcd_app_version"
app_type: "$CERC_APP_TYPE"
EOF
cat $RECORD_FILE
RECORD_ID=$(laconic -c $CONFIG_FILE cns record publish --filename $RECORD_FILE --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} | jq -r '.id')
echo $RECORD_ID
if [ -z "$CERC_REGISTRY_APP_CRN" ]; then
authority=$(echo "$rcd_name" | cut -d'/' -f1 | sed 's/@//')
app=$(echo "$rcd_name" | cut -d'/' -f2-)
CERC_REGISTRY_APP_CRN="crn://$authority/applications/$app"
fi
laconic -c $CONFIG_FILE cns name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_CRN@${rcd_app_version}" "$RECORD_ID"
laconic -c $CONFIG_FILE cns name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_CRN@${CERC_REPO_REF}" "$RECORD_ID"
if [ "true" == "$CERC_IS_LATEST_RELEASE" ]; then
laconic -c $CONFIG_FILE cns name set --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} "$CERC_REGISTRY_APP_CRN" "$RECORD_ID"
fi
rm -f $RECORD_FILE $CONFIG_FILE
-59
View File
@@ -1,59 +0,0 @@
#!/bin/bash
set -e
RECORD_FILE=tmp.rf.$$
CONFIG_FILE=`mktemp`
rcd_name=$(jq -r '.name' package.json | sed 's/null//' | sed 's/^@//')
rcd_app_version=$(jq -r '.version' package.json | sed 's/null//')
cat <<EOF > "$CONFIG_FILE"
services:
cns:
restEndpoint: '${CERC_REGISTRY_REST_ENDPOINT:-http://console.laconic.com:1317}'
gqlEndpoint: '${CERC_REGISTRY_GQL_ENDPOINT:-http://console.laconic.com:9473/api}'
chainId: ${CERC_REGISTRY_CHAIN_ID:-laconic_9000-1}
gas: 1550000
fees: 20000aphoton
EOF
if [ -z "$CERC_REGISTRY_APP_CRN" ]; then
authority=$(echo "$rcd_name" | cut -d'/' -f1 | sed 's/@//')
app=$(echo "$rcd_name" | cut -d'/' -f2-)
CERC_REGISTRY_APP_CRN="crn://$authority/applications/$app"
fi
APP_RECORD=$(laconic -c $CONFIG_FILE cns name resolve "$CERC_REGISTRY_APP_CRN" | jq '.[0]')
if [ -z "$APP_RECORD" ] || [ "null" == "$APP_RECORD" ]; then
echo "No record found for $CERC_REGISTRY_APP_CRN."
exit 1
fi
cat <<EOF | sed '/.*: ""$/d' > "$RECORD_FILE"
record:
type: ApplicationDeploymentRequest
version: 1.0.0
name: "$rcd_name@$rcd_app_version"
application: "$CERC_REGISTRY_APP_CRN@$rcd_app_version"
dns: "$CERC_REGISTRY_DEPLOYMENT_SHORT_HOSTNAME"
deployment: "$CERC_REGISTRY_DEPLOYMENT_CRN"
config:
env:
CERC_WEBAPP_DEBUG: "$rcd_app_version"
CERC_MAX_GENERATE_TIME: 180
CERC_NEXT_VERSION: 13.4.2
URL_OSMOSIS_REST: "https://lcd-osmosis.blockapsis.com"
URL_OSMOSIS_RPC: "https://rpc-osmosis.blockapsis.com"
WALLET_CONNECT_ID: "0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0"
meta:
note: "Added by CI @ `date`"
repository: "`git remote get-url origin`"
repository_ref: "${GITHUB_SHA:-`git log -1 --format="%H"`}"
EOF
cat $RECORD_FILE
RECORD_ID=$(laconic -c $CONFIG_FILE cns record publish --filename $RECORD_FILE --user-key "${CERC_REGISTRY_USER_KEY}" --bond-id ${CERC_REGISTRY_BOND_ID} | jq -r '.id')
echo $RECORD_ID
rm -f $RECORD_FILE $CONFIG_FILE
@@ -14,7 +14,7 @@ type Props = {
export default function PnL(props: Props) {
return (
<Tooltip content={<PnLTooltip {...props} />} type='info' underline>
<Tooltip content={<PnLTooltip {...props} />} type='info' underline className='w-min ml-auto'>
<DisplayCurrency
className='inline text-xs'
coin={props.pnl.net}
+1 -1
View File
@@ -104,7 +104,7 @@ export function PerpsModule() {
/>
<AssetAmountInput
label='Amount'
max={BN(100000000)} // TODO: Implement max calculation
max={BN(10000000000)} // TODO: Implement max calculation
amount={amount.abs()}
setAmount={onChangeAmount}
asset={perpsAsset}
+9 -1
View File
@@ -3,6 +3,7 @@ import BigNumber from 'bignumber.js'
import { CircularProgress } from 'components/common/CircularProgress'
import DisplayCurrency from 'components/common/DisplayCurrency'
import useTradingFeeAndPrice from 'hooks/perps/useTradingFeeAndPrice'
import { BNCoin } from 'types/classes/BNCoin'
type Props = {
denom: string
@@ -20,5 +21,12 @@ export default function TradingFee(props: Props) {
if (isLoading) return <CircularProgress className='h-full' size={12} />
if (props.newAmount.isEqualTo(props.previousAmount) || !tradingFeeAndPrice?.fee) return '-'
return <DisplayCurrency coin={tradingFeeAndPrice.fee} />
return (
<DisplayCurrency
coin={BNCoin.fromDenomAndBigNumber(
tradingFeeAndPrice.baseDenom,
tradingFeeAndPrice.fee.opening.plus(tradingFeeAndPrice.fee.closing),
)}
/>
)
}
+12 -14
View File
@@ -6,7 +6,6 @@ import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useChainConfig from 'hooks/useChainConfig'
import useClients from 'hooks/useClients'
import useDebounce from 'hooks/useDebounce'
import { BNCoin } from 'types/classes/BNCoin'
import { BN } from 'utils/helpers'
export default function useTradingFeeAndPrice(
@@ -34,14 +33,15 @@ export default function useTradingFeeAndPrice(
})
return {
baseDenom: positionFees.base_denom,
price: positionFees.opening_exec_price
? BN(positionFees.opening_exec_price)
: BN(positionFees.closing_exec_price ?? BN_ZERO),
fee: BNCoin.fromDenomAndBigNumber(
positionFees.base_denom,
BN(positionFees.opening_fee).plus(positionFees.closing_fee),
),
rate: BN(0.005),
fee: {
opening: BN(positionFees.opening_fee),
closing: BN(positionFees.closing_fee),
},
rate: BN(0.0005),
}
}
@@ -61,15 +61,13 @@ export default function useTradingFeeAndPrice(
return await Promise.all([closingPositionFees$, openingPositionFees$]).then(
([closingPositionFees, openingPositionFees]) => ({
baseDenom: openingPositionFees.base_denom,
price: BN(openingPositionFees.opening_exec_price ?? 0),
fee: BNCoin.fromDenomAndBigNumber(
closingPositionFees.base_denom,
BN(closingPositionFees.opening_fee)
.plus(closingPositionFees.closing_fee)
.plus(openingPositionFees.opening_fee)
.plus(openingPositionFees.closing_fee),
),
rate: BN(0.005),
fee: {
opening: BN(closingPositionFees.opening_fee).plus(openingPositionFees.opening_fee),
closing: BN(closingPositionFees.closing_fee).plus(openingPositionFees.closing_fee),
},
rate: BN(0.0005), // TODO: Make this rate the actula rate again!
}),
)
},
+7 -4
View File
@@ -14,6 +14,7 @@ import { VaultConfigBaseForString } from 'types/generated/mars-params/MarsParams
import {
AssetParamsBaseForAddr,
HealthComputer,
Positions,
} from 'types/generated/mars-rover-health-computer/MarsRoverHealthComputer.types'
import { convertAccountToPositions } from 'utils/accounts'
import { byDenom } from 'utils/array'
@@ -32,7 +33,8 @@ import { BN } from 'utils/helpers'
// Pyth returns prices with up to 32 decimals. Javascript only supports 18 decimals. So we need to scale by 14 t
// avoid "too many decimals" errors.
const VALUE_SCALE_FACTOR = 14
// TODO: Remove adjustment properly (after testing). We will just ignore the last 14 decimals.
const VALUE_SCALE_FACTOR = 0
export default function useHealthComputer(account?: Account) {
const assets = useAllAssets()
@@ -42,10 +44,10 @@ export default function useHealthComputer(account?: Account) {
const [slippage] = useLocalStorage<number>(LocalStorageKeys.SLIPPAGE, DEFAULT_SETTINGS.slippage)
const [healthFactor, setHealthFactor] = useState(0)
const positions: PositionsWithoutPerps | null = useMemo(() => {
const positions: Positions | null = useMemo(() => {
if (!account) return null
return convertAccountToPositions(account)
}, [account])
return convertAccountToPositions(account, prices)
}, [account, prices])
const vaultPositionValues = useMemo(() => {
if (!account?.vaults) return null
@@ -87,6 +89,7 @@ export default function useHealthComputer(account?: Account) {
prev[curr.denom] = curr.amount
.shiftedBy(VALUE_SCALE_FACTOR)
.shiftedBy(-decimals + 6)
.decimalPlaces(18)
.toString()
return prev
},
+20 -4
View File
@@ -1,4 +1,4 @@
import { ActionCoin } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
import { ActionCoin, PnL } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
import { BN } from 'utils/helpers'
export class BNCoin {
@@ -23,7 +23,7 @@ export class BNCoin {
toCoin(): Coin {
return {
denom: this.denom,
amount: this.amount.toString(),
amount: this.amount.integerValue().toString(),
}
}
@@ -33,7 +33,7 @@ export class BNCoin {
amount: max
? 'account_balance'
: {
exact: this.amount.toString(),
exact: this.amount.integerValue().toString(),
},
}
}
@@ -41,7 +41,23 @@ export class BNCoin {
toSignedCoin(): any {
return {
denom: this.denom,
size: this.amount.toString(),
size: this.amount.integerValue().toString(),
}
}
toPnLCoin(): PnL {
if (this.amount.isZero()) {
return 'break_even'
}
if (this.amount.isPositive()) {
return {
profit: this.toCoin(),
}
}
return {
loss: this.abs().toCoin(),
}
}
@@ -69,6 +69,7 @@ import {
Positions,
DebtAmount,
PerpPosition,
PnlAmounts,
PositionPnl,
PnlCoins,
PnlValues,
@@ -28,387 +28,387 @@ export interface InstantiateMsg {
}
export type ExecuteMsg =
| {
create_credit_account: AccountKind
}
create_credit_account: AccountKind
}
| {
update_credit_account: {
account_id: string
actions: Action[]
}
}
update_credit_account: {
account_id: string
actions: Action[]
}
}
| {
repay_from_wallet: {
account_id: string
}
}
repay_from_wallet: {
account_id: string
}
}
| {
update_config: {
updates: ConfigUpdates
}
}
update_config: {
updates: ConfigUpdates
}
}
| {
update_owner: OwnerUpdate
}
update_owner: OwnerUpdate
}
| {
update_nft_config: {
config?: NftConfigUpdates | null
ownership?: Action2 | null
}
}
update_nft_config: {
config?: NftConfigUpdates | null
ownership?: Action2 | null
}
}
| {
callback: CallbackMsg
}
callback: CallbackMsg
}
export type AccountKind = 'default' | 'high_levered_strategy'
export type Action =
| {
deposit: Coin
}
deposit: Coin
}
| {
withdraw: ActionCoin
}
withdraw: ActionCoin
}
| {
borrow: Coin
}
borrow: Coin
}
| {
lend: ActionCoin
}
lend: ActionCoin
}
| {
reclaim: ActionCoin
}
reclaim: ActionCoin
}
| {
claim_rewards: {}
}
claim_rewards: {}
}
| {
repay: {
coin: ActionCoin
recipient_account_id?: string | null
}
}
repay: {
coin: ActionCoin
recipient_account_id?: string | null
}
}
| {
open_perp: {
denom: string
size: SignedDecimal
}
}
open_perp: {
denom: string
size: SignedDecimal
}
}
| {
close_perp: {
denom: string
}
}
close_perp: {
denom: string
}
}
| {
modify_perp: {
denom: string
new_size: SignedDecimal
}
}
modify_perp: {
denom: string
new_size: SignedDecimal
}
}
| {
enter_vault: {
coin: ActionCoin
vault: VaultBaseForString
}
}
enter_vault: {
coin: ActionCoin
vault: VaultBaseForString
}
}
| {
exit_vault: {
amount: Uint128
vault: VaultBaseForString
}
}
exit_vault: {
amount: Uint128
vault: VaultBaseForString
}
}
| {
request_vault_unlock: {
amount: Uint128
vault: VaultBaseForString
}
}
request_vault_unlock: {
amount: Uint128
vault: VaultBaseForString
}
}
| {
exit_vault_unlocked: {
id: number
vault: VaultBaseForString
}
}
exit_vault_unlocked: {
id: number
vault: VaultBaseForString
}
}
| {
liquidate: {
debt_coin: Coin
liquidatee_account_id: string
request: LiquidateRequestForVaultBaseForString
}
}
liquidate: {
debt_coin: Coin
liquidatee_account_id: string
request: LiquidateRequestForVaultBaseForString
}
}
| {
swap_exact_in: {
coin_in: ActionCoin
denom_out: string
slippage: Decimal
}
}
swap_exact_in: {
coin_in: ActionCoin
denom_out: string
slippage: Decimal
}
}
| {
provide_liquidity: {
coins_in: ActionCoin[]
lp_token_out: string
slippage: Decimal
}
}
provide_liquidity: {
coins_in: ActionCoin[]
lp_token_out: string
slippage: Decimal
}
}
| {
withdraw_liquidity: {
lp_token: ActionCoin
slippage: Decimal
}
}
withdraw_liquidity: {
lp_token: ActionCoin
slippage: Decimal
}
}
| {
refund_all_coin_balances: {}
}
refund_all_coin_balances: {}
}
export type ActionAmount =
| 'account_balance'
| {
exact: Uint128
}
exact: Uint128
}
export type LiquidateRequestForVaultBaseForString =
| {
deposit: string
}
deposit: string
}
| {
lend: string
}
lend: string
}
| {
vault: {
position_type: VaultPositionType
request_vault: VaultBaseForString
}
}
vault: {
position_type: VaultPositionType
request_vault: VaultBaseForString
}
}
export type VaultPositionType = 'u_n_l_o_c_k_e_d' | 'l_o_c_k_e_d' | 'u_n_l_o_c_k_i_n_g'
export type AccountNftBaseForString = string
export type PerpsBaseForString = string
export type OwnerUpdate =
| {
propose_new_owner: {
proposed: string
}
}
propose_new_owner: {
proposed: string
}
}
| 'clear_proposed'
| 'accept_proposed'
| 'abolish_owner_role'
| {
set_emergency_owner: {
emergency_owner: string
}
}
set_emergency_owner: {
emergency_owner: string
}
}
| 'clear_emergency_owner'
export type Action2 =
| {
transfer_ownership: {
expiry?: Expiration | null
new_owner: string
}
}
transfer_ownership: {
expiry?: Expiration | null
new_owner: string
}
}
| 'accept_ownership'
| 'renounce_ownership'
export type Expiration =
| {
at_height: number
}
at_height: number
}
| {
at_time: Timestamp
}
at_time: Timestamp
}
| {
never: {}
}
never: {}
}
export type Timestamp = Uint64
export type Uint64 = string
export type CallbackMsg =
| {
withdraw: {
account_id: string
coin: ActionCoin
recipient: Addr
}
}
withdraw: {
account_id: string
coin: ActionCoin
recipient: Addr
}
}
| {
borrow: {
account_id: string
coin: Coin
}
}
borrow: {
account_id: string
coin: Coin
}
}
| {
repay: {
account_id: string
coin: ActionCoin
}
}
repay: {
account_id: string
coin: ActionCoin
}
}
| {
repay_for_recipient: {
benefactor_account_id: string
coin: ActionCoin
recipient_account_id: string
}
}
repay_for_recipient: {
benefactor_account_id: string
coin: ActionCoin
recipient_account_id: string
}
}
| {
lend: {
account_id: string
coin: ActionCoin
}
}
lend: {
account_id: string
coin: ActionCoin
}
}
| {
reclaim: {
account_id: string
coin: ActionCoin
}
}
reclaim: {
account_id: string
coin: ActionCoin
}
}
| {
claim_rewards: {
account_id: string
recipient: Addr
}
}
claim_rewards: {
account_id: string
recipient: Addr
}
}
| {
assert_max_ltv: {
account_id: string
prev_health_state: HealthState
}
}
assert_max_ltv: {
account_id: string
prev_health_state: HealthState
}
}
| {
assert_deposit_caps: {
denoms: string[]
}
}
assert_deposit_caps: {
denoms: string[]
}
}
| {
open_perp: {
account_id: string
denom: string
size: SignedDecimal
}
}
open_perp: {
account_id: string
denom: string
size: SignedDecimal
}
}
| {
close_perp: {
account_id: string
denom: string
}
}
close_perp: {
account_id: string
denom: string
}
}
| {
modify_perp: {
account_id: string
denom: string
new_size: SignedDecimal
}
}
modify_perp: {
account_id: string
denom: string
new_size: SignedDecimal
}
}
| {
enter_vault: {
account_id: string
coin: ActionCoin
vault: VaultBaseForAddr
}
}
enter_vault: {
account_id: string
coin: ActionCoin
vault: VaultBaseForAddr
}
}
| {
exit_vault: {
account_id: string
amount: Uint128
vault: VaultBaseForAddr
}
}
exit_vault: {
account_id: string
amount: Uint128
vault: VaultBaseForAddr
}
}
| {
update_vault_coin_balance: {
account_id: string
previous_total_balance: Uint128
vault: VaultBaseForAddr
}
}
update_vault_coin_balance: {
account_id: string
previous_total_balance: Uint128
vault: VaultBaseForAddr
}
}
| {
request_vault_unlock: {
account_id: string
amount: Uint128
vault: VaultBaseForAddr
}
}
request_vault_unlock: {
account_id: string
amount: Uint128
vault: VaultBaseForAddr
}
}
| {
exit_vault_unlocked: {
account_id: string
position_id: number
vault: VaultBaseForAddr
}
}
exit_vault_unlocked: {
account_id: string
position_id: number
vault: VaultBaseForAddr
}
}
| {
liquidate: {
debt_coin: Coin
liquidatee_account_id: string
liquidator_account_id: string
request: LiquidateRequestForVaultBaseForAddr
}
}
liquidate: {
debt_coin: Coin
liquidatee_account_id: string
liquidator_account_id: string
request: LiquidateRequestForVaultBaseForAddr
}
}
| {
swap_exact_in: {
account_id: string
coin_in: ActionCoin
denom_out: string
slippage: Decimal
}
}
swap_exact_in: {
account_id: string
coin_in: ActionCoin
denom_out: string
slippage: Decimal
}
}
| {
update_coin_balance: {
account_id: string
change: ChangeExpected
previous_balance: Coin
}
}
update_coin_balance: {
account_id: string
change: ChangeExpected
previous_balance: Coin
}
}
| {
update_coin_balance_after_vault_liquidation: {
account_id: string
previous_balance: Coin
protocol_fee: Decimal
}
}
update_coin_balance_after_vault_liquidation: {
account_id: string
previous_balance: Coin
protocol_fee: Decimal
}
}
| {
provide_liquidity: {
account_id: string
coins_in: ActionCoin[]
lp_token_out: string
slippage: Decimal
}
}
provide_liquidity: {
account_id: string
coins_in: ActionCoin[]
lp_token_out: string
slippage: Decimal
}
}
| {
withdraw_liquidity: {
account_id: string
lp_token: ActionCoin
slippage: Decimal
}
}
withdraw_liquidity: {
account_id: string
lp_token: ActionCoin
slippage: Decimal
}
}
| {
refund_all_coin_balances: {
account_id: string
}
}
refund_all_coin_balances: {
account_id: string
}
}
| {
assert_hls_rules: {
account_id: string
}
}
assert_hls_rules: {
account_id: string
}
}
| {
remove_reentrancy_guard: {}
}
remove_reentrancy_guard: {}
}
| {
send_rewards_to_addr: {
account_id: string
previous_balances: Coin[]
recipient: Addr
}
}
send_rewards_to_addr: {
account_id: string
previous_balances: Coin[]
recipient: Addr
}
}
export type Addr = string
export type HealthState =
| 'healthy'
| {
unhealthy: {
max_ltv_health_factor: Decimal
}
}
unhealthy: {
max_ltv_health_factor: Decimal
}
}
export type LiquidateRequestForVaultBaseForAddr =
| {
deposit: string
}
deposit: string
}
| {
lend: string
}
lend: string
}
| {
vault: {
position_type: VaultPositionType
request_vault: VaultBaseForAddr
}
}
vault: {
position_type: VaultPositionType
request_vault: VaultBaseForAddr
}
}
export type ChangeExpected = 'increase' | 'decrease'
export interface Coin {
amount: Uint128
@@ -451,80 +451,80 @@ export interface VaultBaseForAddr {
}
export type QueryMsg =
| {
account_kind: {
account_id: string
}
}
account_kind: {
account_id: string
}
}
| {
accounts: {
limit?: number | null
owner: string
start_after?: string | null
}
}
accounts: {
limit?: number | null
owner: string
start_after?: string | null
}
}
| {
config: {}
}
config: {}
}
| {
vault_utilization: {
vault: VaultBaseForString
}
}
vault_utilization: {
vault: VaultBaseForString
}
}
| {
positions: {
account_id: string
}
}
positions: {
account_id: string
}
}
| {
all_coin_balances: {
limit?: number | null
start_after?: [string, string] | null
}
}
all_coin_balances: {
limit?: number | null
start_after?: [string, string] | null
}
}
| {
all_debt_shares: {
limit?: number | null
start_after?: [string, string] | null
}
}
all_debt_shares: {
limit?: number | null
start_after?: [string, string] | null
}
}
| {
total_debt_shares: string
}
total_debt_shares: string
}
| {
all_total_debt_shares: {
limit?: number | null
start_after?: string | null
}
}
all_total_debt_shares: {
limit?: number | null
start_after?: string | null
}
}
| {
all_vault_positions: {
limit?: number | null
start_after?: [string, string] | null
}
}
all_vault_positions: {
limit?: number | null
start_after?: [string, string] | null
}
}
| {
estimate_provide_liquidity: {
coins_in: Coin[]
lp_token_out: string
}
}
estimate_provide_liquidity: {
coins_in: Coin[]
lp_token_out: string
}
}
| {
estimate_withdraw_liquidity: {
lp_token: Coin
}
}
estimate_withdraw_liquidity: {
lp_token: Coin
}
}
| {
vault_position_value: {
vault_position: VaultPosition
}
}
vault_position_value: {
vault_position: VaultPosition
}
}
export type VaultPositionAmount =
| {
unlocked: VaultAmount
}
unlocked: VaultAmount
}
| {
locking: LockingVaultAmount
}
locking: LockingVaultAmount
}
export type VaultAmount = string
export type VaultAmount1 = string
export type UnlockingPositions = VaultUnlockingPosition[]
@@ -597,11 +597,11 @@ export type ArrayOfCoin = Coin[]
export type PnL =
| 'break_even'
| {
profit: Coin
}
profit: Coin
}
| {
loss: Coin
}
loss: Coin
}
export interface Positions {
account_id: string
debts: DebtAmount[]
@@ -623,11 +623,11 @@ export interface PerpPosition {
denom: string
entry_exec_price: Decimal
entry_price: Decimal
realised_pnl: RealizedPnlAmounts
realised_pnl: PnlAmounts
size: SignedDecimal
unrealised_pnl: PositionPnl
}
export interface RealizedPnlAmounts {
export interface PnlAmounts {
accrued_funding: SignedDecimal
closing_fee: SignedDecimal
opening_fee: SignedDecimal
@@ -635,6 +635,7 @@ export interface RealizedPnlAmounts {
price_pnl: SignedDecimal
}
export interface PositionPnl {
amounts: PnlAmounts
coins: PnlCoins
values: PnlValues
}
@@ -27,10 +27,11 @@ import {
DebtAmount,
Coin,
PerpPosition,
PnlAmounts,
SignedDecimal,
PositionPnl,
PnlCoins,
PnlValues,
SignedDecimal,
VaultPosition,
LockingVaultAmount,
VaultUnlockingPosition,
@@ -27,10 +27,11 @@ import {
DebtAmount,
Coin,
PerpPosition,
PnlAmounts,
SignedDecimal,
PositionPnl,
PnlCoins,
PnlValues,
SignedDecimal,
VaultPosition,
LockingVaultAmount,
VaultUnlockingPosition,
@@ -41,7 +41,7 @@ export type UnlockingPositions = VaultUnlockingPosition[]
export interface HealthComputer {
denoms_data: DenomsData
kind: AccountKind
positions: PositionsWithoutPerps
positions: Positions
vaults_data: VaultsData
}
export interface DenomsData {
@@ -102,13 +102,29 @@ export interface Coin {
export interface PerpPosition {
base_denom: string
closing_fee_rate: Decimal
current_exec_price: Decimal
current_price: Decimal
denom: string
entry_exec_price: Decimal
entry_price: Decimal
pnl: PositionPnl
realised_pnl: PnlAmounts
size: SignedDecimal
unrealised_pnl: PositionPnl
}
export interface PnlAmounts {
accrued_funding: SignedDecimal
closing_fee: SignedDecimal
opening_fee: SignedDecimal
pnl: SignedDecimal
price_pnl: SignedDecimal
}
export interface SignedDecimal {
abs: Decimal
negative: boolean
[k: string]: unknown
}
export interface PositionPnl {
amounts: PnlAmounts
coins: PnlCoins
values: PnlValues
}
@@ -122,11 +138,6 @@ export interface PnlValues {
pnl: SignedDecimal
price_pnl: SignedDecimal
}
export interface SignedDecimal {
abs: Decimal
negative: boolean
[k: string]: unknown
}
export interface VaultPosition {
amount: VaultPositionAmount
vault: VaultBaseForAddr
+1 -6
View File
@@ -1,11 +1,5 @@
type TradeDirection = 'long' | 'short'
// TODO: 📈Remove this type when healthcomputer is implemented
type PositionsWithoutPerps = Omit<
import('types/generated/mars-credit-manager/MarsCreditManager.types').Positions,
'perps'
>
interface PerpsPosition {
denom: string
baseDenom: string
@@ -13,6 +7,7 @@ interface PerpsPosition {
amount: BigNumber
pnl: PerpsPnL
entryPrice: BigNumber
closingFeeRate: BigNumber
}
interface PerpPositionRow extends PerpsPosition {
+62 -1
View File
@@ -4,6 +4,7 @@ import { BN_ZERO } from 'constants/math'
import { ORACLE_DENOM } from 'constants/oracle'
import { BNCoin } from 'types/classes/BNCoin'
import { VaultPosition } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
import { Positions } from 'types/generated/mars-rover-health-computer/MarsRoverHealthComputer.types'
import { byDenom } from 'utils/array'
import { BN } from 'utils/helpers'
import { convertApyToApr } from 'utils/parsers'
@@ -174,7 +175,7 @@ export function accumulateAmounts(denom: string, coins: BNCoin[]): BigNumber {
}
// TODO: 📈 Add correct type mapping
export function convertAccountToPositions(account: Account): PositionsWithoutPerps {
export function convertAccountToPositions(account: Account, prices: BNCoin[]): Positions {
return {
account_id: account.id,
debts: account.debts.map((debt) => ({
@@ -188,6 +189,66 @@ export function convertAccountToPositions(account: Account): PositionsWithoutPer
amount: lend.amount.toString(),
denom: lend.denom,
})),
perps: account.perps.map((perpPosition) => {
// TODO: Check if this needs to be converted (in regards to HC decimal scaling)
const currentPrice = prices.find(byDenom(perpPosition.denom))?.amount ?? BN_ZERO
return {
// Used
base_denom: perpPosition.baseDenom,
// Used
closing_fee_rate: perpPosition.closingFeeRate.toString(),
// Used
current_price: currentPrice.toString(), // Check what prices we should pass to current and entry prices. Entry price will change when modifying positionl
current_exec_price: currentPrice.toString(), // TODO: 📈 This needs to be queried
denom: perpPosition.denom,
// Used (for now, this might be changed)
entry_price: currentPrice.toString(),
// Used (not actually used, but it's in todo)
entry_exec_price: currentPrice.toString(), // TODO: 📈 Check if this matters (currently just using entry price)
// Used
size: perpPosition.amount.toString() as any,
unrealised_pnl: {
coins: {
closing_fee: perpPosition.pnl.unrealized.fees.abs().toCoin(),
// Used
pnl: perpPosition.pnl.unrealized.net.toPnLCoin(), // Used
},
amounts: {
// CHeck if these are correct
accrued_funding: perpPosition.pnl.unrealized.funding.amount
.integerValue()
.toString() as any,
opening_fee: perpPosition.pnl.unrealized.fees.amount
.abs()
.integerValue()
.toString() as any, // Add openning fee for modifying position
closing_fee: perpPosition.pnl.unrealized.fees.amount
.abs()
.integerValue()
.toString() as any, // Add closing fee for modifying position
pnl: perpPosition.pnl.unrealized.net.amount.integerValue().toString() as any,
price_pnl: perpPosition.pnl.unrealized.price.amount.integerValue().toString() as any,
},
values: {
// This does not matter for health calculation
accrued_funding: perpPosition.pnl.unrealized.funding.amount
.integerValue()
.toString() as any,
closing_fee: perpPosition.pnl.unrealized.fees.amount.integerValue().toString() as any,
pnl: perpPosition.pnl.unrealized.net.amount.integerValue().toString() as any,
price_pnl: perpPosition.pnl.unrealized.price.amount.integerValue().toString() as any,
},
},
realised_pnl: {
// This does not matter for the health calculation
accrued_funding: perpPosition.pnl.realized.funding.amount.toString() as any,
closing_fee: perpPosition.pnl.realized.fees.amount.toString() as any,
opening_fee: perpPosition.pnl.realized.fees.amount.toString() as any,
pnl: perpPosition.pnl.realized.net.amount.toString() as any,
price_pnl: perpPosition.pnl.realized.price.amount.toString() as any,
},
}
}),
vaults: account.vaults.map(
(vault) =>
({
+3 -2
View File
@@ -2,16 +2,17 @@ import BigNumber from 'bignumber.js'
import { BN_ONE, BN_ZERO } from 'constants/math'
import { BNCoin } from 'types/classes/BNCoin'
import { BN } from 'utils/helpers'
export default function getPerpsPosition(
asset: Asset,
amount: BigNumber,
tradeDirection: TradeDirection,
) {
): PerpsPosition {
const perpsBaseDenom = 'ibc/F91EA2C0A23697A1048E08C2F787E3A58AC6F706A1CD2257A504925158CFC0F3'
return {
amount,
closingFee: BNCoin.fromDenomAndBigNumber(perpsBaseDenom, BN_ONE),
closingFeeRate: BN(0.0005), // TODO: Pass the actual rate
pnl: {
net: BNCoin.fromDenomAndBigNumber(perpsBaseDenom, BN_ONE),
realized: {
+1 -1
View File
@@ -96,10 +96,10 @@ export interface InitOutput {
h: number,
) => void
readonly liquidation_price_js: (a: number, b: number, c: number, d: number, e: number) => void
readonly interface_version_8: () => void
readonly allocate: (a: number) => number
readonly deallocate: (a: number) => void
readonly requires_iterator: () => void
readonly interface_version_8: () => void
readonly __wbindgen_malloc: (a: number, b: number) => number
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number
readonly __wbindgen_add_to_stack_pointer: (a: number) => number
+1
View File
@@ -296,6 +296,7 @@ async function __wbg_load(module, imports) {
function __wbg_get_imports() {
const imports = {}
imports.wbg = {}
imports.wbg.__wbg_log_117d9799fa4f6287 = function (arg0, arg1, arg2, arg3) {}
imports.wbg.__wbindgen_object_clone_ref = function (arg0) {
const ret = getObject(arg0)
return addHeapObject(ret)
Binary file not shown.
+1 -1
View File
@@ -15,10 +15,10 @@ export function max_swap_estimate_js(
h: number,
): void
export function liquidation_price_js(a: number, b: number, c: number, d: number, e: number): void
export function interface_version_8(): void
export function allocate(a: number): number
export function deallocate(a: number): void
export function requires_iterator(): void
export function interface_version_8(): void
export function __wbindgen_malloc(a: number, b: number): number
export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number
export function __wbindgen_add_to_stack_pointer(a: number): number
+1 -1
View File
@@ -118,7 +118,7 @@ export function resolvePerpsPositions(
baseDenom: position.base_denom,
amount: BN(position.size as any), // Amount is negative for SHORT positions
tradeDirection: BN(position.size as any).isNegative() ? 'short' : 'long',
// closingFee: BNCoin.fromCoin(position.pnl.coins.closing_fee),
closingFeeRate: BN(position.closing_fee_rate),
pnl: {
net: BNCoin.fromDenomAndBigNumber(
position.base_denom,