diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 4ee11b62..740fe7b6 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -24,4 +24,3 @@ jobs: - uses: oven-sh/setup-bun@v2 - run: bun install - run: bunx tsc --noemit - diff --git a/src/lib/state/client/account.svelte.ts b/src/lib/state/client/account.svelte.ts index 83c85c5e..46e5bf72 100644 --- a/src/lib/state/client/account.svelte.ts +++ b/src/lib/state/client/account.svelte.ts @@ -21,7 +21,8 @@ const defaultDataSources = { get_account: undefined, light_account: [], delegated: [], - rex: undefined + rex: undefined, + rexfund: undefined }; export class AccountState { @@ -79,7 +80,8 @@ export class AccountState { get_account: json.account_data, light_account: json.balances, delegated: json.delegated, - rex: json.rex + rex: json.rex, + rexfund: json.rexfund }; this.account = new Account({ client: this.network.client, @@ -192,13 +194,19 @@ export function getBalance(network: NetworkState, sources: DataSources): Balance total.units.add(delegatedTokens.units); } - // Add any staked (REX) tokens to total balance based on current value - if (sources.rex) { - if (network.config.features.rex && network.rexstate) { - const rex = network.rexToToken(sources.rex.rex_balance); - // const rex = convertRexToToken(sources.rex.rex_balance, network.rexstate); - staked.units.add(rex.units); - total.units.add(rex.units); + if (network.config.features.rex) { + // Add any staked (REX) tokens to total balance based on current value + if (sources.rex) { + if (network.rexstate) { + const rex = network.rexToToken(sources.rex.rex_balance); + staked.units.add(rex.units); + total.units.add(rex.units); + } + } + // Add rex fund to total balance based on current value + if (sources.rexfund && sources.rexfund.balance) { + staked.units.add(sources.rexfund.balance.units); + total.units.add(sources.rexfund.balance.units); } } diff --git a/src/lib/types.ts b/src/lib/types.ts index 9515c36c..dd03ada3 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -36,6 +36,7 @@ export interface DataSources { light_account: LightAPIBalanceResponse[]; delegated: SystemContract.Types.delegated_bandwidth[]; rex?: SystemContract.Types.rex_balance; + rexfund?: SystemContract.Types.rex_fund; } export interface LightAPIBalanceRow { diff --git a/src/routes/[network]/(account)/(staking)/staking/+layout.svelte b/src/routes/[network]/(account)/(staking)/staking/+layout.svelte index 845cd74f..60ccafca 100644 --- a/src/routes/[network]/(account)/(staking)/staking/+layout.svelte +++ b/src/routes/[network]/(account)/(staking)/staking/+layout.svelte @@ -34,10 +34,8 @@ - - - - + + {@render children()} diff --git a/src/routes/[network]/(account)/(staking)/staking/+page.svelte b/src/routes/[network]/(account)/(staking)/staking/+page.svelte index 8cd019fb..b6fa544e 100644 --- a/src/routes/[network]/(account)/(staking)/staking/+page.svelte +++ b/src/routes/[network]/(account)/(staking)/staking/+page.svelte @@ -9,6 +9,7 @@ import type { UnstakingRecord, WithdrawableBalance } from './utils'; import { getStakedBalance, getUnstakingBalances, getAPY } from './utils'; + import UnstakingBalances from './unstaking.svelte'; const context = getContext('state'); const { data } = $props(); @@ -46,39 +47,7 @@ > - - - - - - - - - - - {#each unstaking as record} - {#if !record.savings} - - - - {/if} - {/each} - -
AmountDate available
{record.balance}{record.date - ? record.date.toLocaleDateString(undefined, { - weekday: 'long', - year: 'numeric', - month: 'long', - day: 'numeric' - }) - : '--'} -
- -
+ diff --git a/src/routes/[network]/(account)/(staking)/staking/stake/+page.svelte b/src/routes/[network]/(account)/(staking)/staking/stake/+page.svelte index f58df239..ede95eb6 100644 --- a/src/routes/[network]/(account)/(staking)/staking/stake/+page.svelte +++ b/src/routes/[network]/(account)/(staking)/staking/stake/+page.svelte @@ -6,32 +6,25 @@ import AssetInput from '$lib/components/input/asset.svelte'; import Button from '$lib/components/button/button.svelte'; import Label from '$lib/components/input/label.svelte'; + import Transaction from '$lib/components/transaction.svelte'; import * as m from '$lib/paraglide/messages.js'; import type { UnicoveContext } from '$lib/state/client.svelte'; import { getContext, untrack } from 'svelte'; - import { StakeState } from './state.svelte'; + import { StakeManager } from './manager.svelte'; const context = getContext('state'); const { data } = $props(); - let stakeState: StakeState = $state(new StakeState(data.network)); + let manager: StakeManager = $state(new StakeManager(data.network)); $effect(() => { - stakeState.sync(data.network, context.account, context.wharf); + manager.sync(data.network, context.account, context.wharf); }); -{#if stakeState.txid} -
-

Transaction Complete

-

success

-

- - {stakeState.txid} - -

-
-{:else if stakeState.error} +{#if manager.txid} + +{:else if manager.error}

Transaction Error

There was an error submitting your transaction.

@@ -44,28 +37,28 @@ - {#if !stakeState.assetValid} - {#if !stakeState.assetValidPrecision} + {#if !manager.assetValid} + {#if !manager.assetValidPrecision}

Invalid number, too many decimal places.

{/if} - {#if !stakeState.assetValidMaximum} + {#if !manager.assetValidMaximum}

Amount exceeds available balance.

{/if} {/if} @@ -74,9 +67,9 @@ Available: {manager.stakable} @@ -88,11 +81,11 @@

Minimum lockup

21 Days

~APY

-

{stakeState.apy}%

+

{manager.apy}%

You will stake

-

{stakeState.assetValid ? stakeState.assetValue : ''}

+

{manager.assetValid ? manager.assetValue : ''}

Estimated Yield(per year)

-

{stakeState.assetValid ? stakeState.estimateYield : ''}

+

{manager.assetValid ? manager.estimateYield : ''}

diff --git a/src/routes/[network]/(account)/(staking)/staking/stake/state.svelte.ts b/src/routes/[network]/(account)/(staking)/staking/stake/manager.svelte.ts similarity index 67% rename from src/routes/[network]/(account)/(staking)/staking/stake/state.svelte.ts rename to src/routes/[network]/(account)/(staking)/staking/stake/manager.svelte.ts index 22f527bb..8a3f1c3c 100644 --- a/src/routes/[network]/(account)/(staking)/staking/stake/state.svelte.ts +++ b/src/routes/[network]/(account)/(staking)/staking/stake/manager.svelte.ts @@ -6,7 +6,7 @@ import AssetInput from '$lib/components/input/asset.svelte'; import { defaultQuantity, getStakableBalance, getAPY } from '../utils'; -export class StakeState { +export class StakeManager { public input: AssetInput | undefined = $state(); public network: NetworkState | undefined = $state(); public account: AccountState | undefined = $state(); @@ -25,14 +25,14 @@ export class StakeState { public txid: string = $state(''); public stakable: Asset = $derived( - this.account && this.network ? getStakableBalance(this.network!, this.account) : defaultQuantity + this.account && this.network ? getStakableBalance(this.network, this.account) : defaultQuantity ); - public apy: string = $derived(getAPY(this.network)); + public apy: string = $derived(this.network ? getAPY(this.network) : '0'); public estimateYield: Asset = $derived( this.network ? Asset.from( (this.assetValue.value * parseFloat(this.apy)) / 100, - this.network!.chain.systemToken!.symbol + this.network.chain.systemToken!.symbol ) : defaultQuantity ); @@ -42,7 +42,7 @@ export class StakeState { } get zeroValue() { - return Asset.from(0, this.network!.chain.systemToken!.symbol); + return this.network ? Asset.from(0, this.network.chain.systemToken!.symbol) : defaultQuantity; } sync(network: NetworkState, account: AccountState, wharf: WharfState) { @@ -61,15 +61,17 @@ export class StakeState { this.txid = ''; } - if (this.assetValue.symbol !== this.network!.chain.systemToken!.symbol) { + if (this.network && this.assetValue.symbol !== this.network.chain.systemToken!.symbol) { this.input?.set(this.zeroValue); } if (wharf !== this.wharf) { this.wharf = wharf; } - this.minValue = Asset.fromUnits(1, this.network!.chain.systemToken!.symbol).value; - this.maxValue = this.account ? getStakableBalance(this.network!, this.account).value : 0; + if (this.network) { + this.minValue = Asset.fromUnits(1, this.network.chain.systemToken!.symbol).value; + this.maxValue = this.account ? getStakableBalance(this.network, this.account).value : 0; + } } setMaxValue() { @@ -77,17 +79,21 @@ export class StakeState { } async transact() { - const deposit = this.network!.contracts.system.action('deposit', { - owner: this.account!.name!, - amount: this.assetValue! - }); - const buyrex = this.network!.contracts.system.action('buyrex', { - from: this.account!.name!, - amount: this.assetValue! - }); - try { - const result = await this.wharf!.transact({ + if (!this.network || !this.account || !this.account.name || !this.wharf || !this.assetValue) { + throw new Error("Can't sign, data not ready"); + } + + const deposit = this.network.contracts.system.action('deposit', { + owner: this.account.name, + amount: this.assetValue + }); + const buyrex = this.network.contracts.system.action('buyrex', { + from: this.account.name, + amount: this.assetValue + }); + + const result = await this.wharf.transact({ actions: [deposit, buyrex] }); diff --git a/src/routes/[network]/(account)/(staking)/staking/unstake/+page.svelte b/src/routes/[network]/(account)/(staking)/staking/unstake/+page.svelte index a84fe0c6..49d09d38 100644 --- a/src/routes/[network]/(account)/(staking)/staking/unstake/+page.svelte +++ b/src/routes/[network]/(account)/(staking)/staking/unstake/+page.svelte @@ -6,32 +6,25 @@ import AssetInput from '$lib/components/input/asset.svelte'; import Button from '$lib/components/button/button.svelte'; import Label from '$lib/components/input/label.svelte'; + import Transaction from '$lib/components/transaction.svelte'; import * as m from '$lib/paraglide/messages.js'; import type { UnicoveContext } from '$lib/state/client.svelte'; import { getContext } from 'svelte'; - import { UnstakeState } from './state.svelte'; + import { UnstakeManager } from './state.svelte'; const context = getContext('state'); const { data } = $props(); - let unstakeState: UnstakeState = $state(new UnstakeState(data.network)); + let manager: UnstakeManager = $state(new UnstakeManager(data.network)); $effect(() => { - unstakeState.sync(data.network, context.account, context.wharf); + manager.sync(data.network, context.account, context.wharf); }); -{#if unstakeState.txid} -
-

Transaction Complete

-

success

-

- - {unstakeState.txid} - -

-
-{:else if unstakeState.error} +{#if manager.txid} + +{:else if manager.error}

Transaction Error

There was an error submitting your transaction.

@@ -44,29 +37,29 @@ - {#if !unstakeState.assetValid} - {#if !unstakeState.assetValidPrecision} + {#if !manager.assetValid} + {#if !manager.assetValidPrecision}

Invalid number, too many decimal places.

{/if} - {#if !unstakeState.assetValidMaximum} + {#if !manager.assetValidMaximum}

Amount exceeds available balance.

{/if} {/if} @@ -75,9 +68,9 @@ Available: {manager.unstakable} @@ -87,7 +80,7 @@

In 21 days you can claim

-

{unstakeState.assetValid ? unstakeState.assetValue : ''}

+

{manager.assetValid ? manager.assetValue : ''}

Lockup

21 Days

diff --git a/src/routes/[network]/(account)/(staking)/staking/unstake/state.svelte.ts b/src/routes/[network]/(account)/(staking)/staking/unstake/manager.svelte.ts similarity index 62% rename from src/routes/[network]/(account)/(staking)/staking/unstake/state.svelte.ts rename to src/routes/[network]/(account)/(staking)/staking/unstake/manager.svelte.ts index 83d26d36..6bc62ae9 100644 --- a/src/routes/[network]/(account)/(staking)/staking/unstake/state.svelte.ts +++ b/src/routes/[network]/(account)/(staking)/staking/unstake/manager.svelte.ts @@ -4,9 +4,10 @@ import type { NetworkState } from '$lib/state/network.svelte'; import type { WharfState } from '$lib/state/client/wharf.svelte'; import AssetInput from '$lib/components/input/asset.svelte'; -import { defaultQuantity, getUnstakableBalance } from '../utils'; +import type { UnstakingRecord } from '../utils'; +import { defaultQuantity, getUnstakableBalance, getUnstakingBalances } from '../utils'; -export class UnstakeState { +export class UnstakeManager { public input: AssetInput | undefined = $state(); public network: NetworkState | undefined = $state(); public account: AccountState | undefined = $state(); @@ -24,8 +25,13 @@ export class UnstakeState { public error: string = $state(''); public txid: string = $state(''); + public unstaking: Array = $derived( + this.account && this.network ? getUnstakingBalances(this.network, this.account) : [] + ); public unstakable: Asset = $derived( - this.account ? getUnstakableBalance(this.network!, this.account) : defaultQuantity + this.account && this.network + ? getUnstakableBalance(this.network, this.account, this.unstaking) + : defaultQuantity ); constructor(network: NetworkState) { @@ -33,7 +39,7 @@ export class UnstakeState { } get zeroValue() { - return Asset.from(0, this.network!.chain.systemToken!.symbol); + return this.network ? Asset.from(0, this.network.chain.systemToken!.symbol) : defaultQuantity; } sync(network: NetworkState, account: AccountState, wharf: WharfState) { @@ -52,15 +58,17 @@ export class UnstakeState { this.txid = ''; } - if (this.assetValue.symbol !== this.network!.chain.systemToken!.symbol) { + if (this.network && this.assetValue.symbol !== this.network.chain.systemToken!.symbol) { this.input?.set(this.zeroValue); } if (wharf !== this.wharf) { this.wharf = wharf; } - this.minValue = Asset.fromUnits(1, this.network!.chain.systemToken!.symbol).value; - this.maxValue = this.account ? getUnstakableBalance(this.network!, this.account).value : 0; + if (this.network) { + this.minValue = Asset.fromUnits(1, this.network.chain.systemToken!.symbol).value; + this.maxValue = this.unstakable.value; + } } setMaxValue() { @@ -68,13 +76,16 @@ export class UnstakeState { } async transact() { - const mvfrsavings = this.network!.contracts.system.action('mvfrsavings', { - owner: this.account!.name!, - rex: this.network!.tokenToRex(this.assetValue!) - }); - try { - const result = await this.wharf!.transact({ + if (!this.network || !this.account || !this.account.name || !this.assetValue || !this.wharf) { + throw new Error("Can't sign, data not ready"); + } + const mvfrsavings = this.network.contracts.system.action('mvfrsavings', { + owner: this.account.name, + rex: this.network.tokenToRex(this.assetValue) + }); + + const result = await this.wharf.transact({ actions: [mvfrsavings] }); diff --git a/src/routes/[network]/(account)/(staking)/staking/unstaking.svelte b/src/routes/[network]/(account)/(staking)/staking/unstaking.svelte new file mode 100644 index 00000000..baf281eb --- /dev/null +++ b/src/routes/[network]/(account)/(staking)/staking/unstaking.svelte @@ -0,0 +1,51 @@ + + + + + + + + + Amount + Date available + + + + {#each records as record} + {#if !record.savings} + + {record.balance} + + {record.date + ? record.date.toLocaleDateString(undefined, { + weekday: 'long', + year: 'numeric', + month: 'long', + day: 'numeric' + }) + : '--'} + + + {/if} + {/each} + + + {#if href} + + {/if} + diff --git a/src/routes/[network]/(account)/(staking)/staking/utils.ts b/src/routes/[network]/(account)/(staking)/staking/utils.ts index f3b0fa01..fd48c749 100644 --- a/src/routes/[network]/(account)/(staking)/staking/utils.ts +++ b/src/routes/[network]/(account)/(staking)/staking/utils.ts @@ -18,54 +18,51 @@ export function getStakableBalance(network: NetworkState, account: AccountState) if (account.balance && account.balance.liquid) { balance.add(account.balance.liquid.units); } - - // TODO: add rexfund } return Asset.fromUnits(balance, network.chain.systemToken!.symbol); } export function getStakedBalance(network: NetworkState, account: AccountState): Asset { - let staked = Asset.fromUnits(0, network.chain.systemToken!.symbol); + let staked = Int64.from(0); if (account && account.loaded) { - const rexInfo = account.account!.data.rex_info; - if (rexInfo) { - staked = network.rexToToken(rexInfo.rex_balance); + if (account.account?.data.rex_info) { + staked.add(network.rexToToken(account.account.data.rex_info.rex_balance).units); + } + if (account.sources.rexfund) { + staked.add(Asset.from(account.sources.rexfund.balance).units); } } - return staked; + return Asset.fromUnits(staked, network.chain.systemToken!.symbol); } export function getClaimableBalance( network: NetworkState, account: AccountState, - unstaking: Array + unstaking: Array | undefined ): Asset { - // withdrawable(rex_fund) + claimable - let claimable: Asset = Asset.from(0, network!.chain.systemToken!.symbol); + // claimable buckets, rex to be sold + let claimable = Int64.from(0); - if (account && account.loaded) { - const rexInfo = account.account!.data.rex_info; - if (rexInfo) { - let matured = Int64.from(0); - const sum: Int64 = unstaking - .filter((r) => r.claimable) - .reduce((acc, r) => acc.adding(r.balance.units), Int64.from(0)); - if (sum) { - matured.add(sum); - } + if (!unstaking) { + unstaking = getUnstakingBalances(network, account); + } - if (matured.gt(Int64.from(0))) { - claimable = Asset.fromUnits(matured, network!.chain.systemToken!.symbol); - } - } + const sum: Int64 = unstaking + .filter((r) => r.claimable) + .reduce((acc, r) => acc.adding(r.balance.units), Int64.from(0)); + if (sum) { + claimable.add(sum); } - return claimable; + return Asset.fromUnits(claimable, network.chain.systemToken!.symbol); } export function getWithdrawableBalance(network: NetworkState, account: AccountState): Asset { - // TODO: add rex fund - return Asset.from(0, network.chain.systemToken!.symbol); + let withdrawable = Int64.from(0); + if (account && account.loaded && account.sources.rexfund && account.sources.rexfund.balance) { + withdrawable.add(Asset.from(account.sources.rexfund.balance).units); + } + return Asset.fromUnits(withdrawable, network.chain.systemToken!.symbol); } export function getUnstakingBalances( @@ -74,48 +71,55 @@ export function getUnstakingBalances( ): Array { // matured_rex + claimable buckets let records: Array = []; - if (account && account.loaded) { - const rexInfo = account.account!.data.rex_info; - if (rexInfo) { - if (rexInfo.matured_rex && rexInfo.matured_rex.gt(Int64.from(0))) { - // add matured into balances - records.push({ - date: undefined, - balance: network.rexToToken( - Asset.fromUnits(rexInfo.matured_rex, rexInfo.rex_balance.symbol) - ), - claimable: true, - savings: false - }); - } + if (account && account.loaded && account.account?.data.rex_info) { + const rexInfo = account.account.data.rex_info; + if (rexInfo.matured_rex && rexInfo.matured_rex.gt(Int64.from(0))) { + // construct matured as one rex bucket + records.push({ + date: undefined, + balance: network.rexToToken( + Asset.fromUnits(rexInfo.matured_rex, rexInfo.rex_balance.symbol) + ), + claimable: true, + savings: false + }); + } + if (rexInfo.rex_maturities) { + // transform real rex buckets const fiveYearsFromNow = new Date().getTime() + 1000 * 60 * 60 * 24 * 365 * 5; const now = new Date(); for (const maturity of rexInfo.rex_maturities) { - const date = new Date(maturity.first!.toString()); - records.push({ - date, - balance: network.rexToToken( - Asset.fromUnits(maturity.second!, rexInfo.rex_balance.symbol) - ), - claimable: +date < +now, - savings: +date > +fiveYearsFromNow - }); + if (maturity.first && maturity.second) { + const date = new Date(maturity.first.toString()); + records.push({ + date, + balance: network.rexToToken( + Asset.fromUnits(maturity.second, rexInfo.rex_balance.symbol) + ), + claimable: +date < +now, + savings: +date > +fiveYearsFromNow + }); + } } } } return records; } -export function getUnstakableBalance(network: NetworkState, account: AccountState): Asset { - const savings = getUnstakingBalances(network, account).find((r) => r.savings); +export function getUnstakableBalance( + network: NetworkState, + account: AccountState, + unstaking: Array | undefined +): Asset { + if (!unstaking) { + unstaking = getUnstakingBalances(network, account); + } + const savings = unstaking.find((r) => r.savings); return savings ? savings.balance : Asset.from(0, network.chain.systemToken!.symbol); } -export function getAPY(network: NetworkState | undefined): string { - if (!network) { - return '0'; - } +export function getAPY(network: NetworkState): string { const annualReward = 31250000; const totalStaked = Number(network.rexstate!.total_lendable.value); return ((annualReward / totalStaked) * 100).toFixed(2); diff --git a/src/routes/[network]/(account)/(staking)/staking/withdraw/+page.svelte b/src/routes/[network]/(account)/(staking)/staking/withdraw/+page.svelte index eb7d6288..4dfa8102 100644 --- a/src/routes/[network]/(account)/(staking)/staking/withdraw/+page.svelte +++ b/src/routes/[network]/(account)/(staking)/staking/withdraw/+page.svelte @@ -7,33 +7,27 @@ import Button from '$lib/components/button/button.svelte'; import Label from '$lib/components/input/label.svelte'; import PageHeader from '$lib/components/pageheader.svelte'; + import Transaction from '$lib/components/transaction.svelte'; import * as m from '$lib/paraglide/messages.js'; import type { UnicoveContext } from '$lib/state/client.svelte'; import { getContext } from 'svelte'; - import { WithdrawState } from './state.svelte'; + import { WithdrawManager } from './state.svelte'; + import UnstakingBalances from '../unstaking.svelte'; const context = getContext('state'); const { data } = $props(); - let withdrawState: WithdrawState = $state(new WithdrawState(data.network)); + let manager: WithdrawManager = $state(new WithdrawManager(data.network)); $effect(() => { - withdrawState.sync(data.network, context.account, context.wharf); + manager.sync(data.network, context.account, context.wharf); }); -{#if withdrawState.txid} -
-

Transaction Complete

-

success

-

- - {withdrawState.txid} - -

-
-{:else if withdrawState.error} +{#if manager.txid} + +{:else if manager.error}

Transaction Error

There was an error submitting your transaction.

@@ -41,44 +35,16 @@ {:else} - + - - - - - - - - - - {#each withdrawState.unstaking as record} - {#if !record.savings} - - - - {/if} - {/each} - -
AmountDate available
{record.balance}{record.date - ? record.date.toLocaleDateString(undefined, { - weekday: 'long', - year: 'numeric', - month: 'long', - day: 'numeric' - }) - : '--'} -
-
+
{/if} diff --git a/src/routes/[network]/(account)/(staking)/staking/withdraw/state.svelte.ts b/src/routes/[network]/(account)/(staking)/staking/withdraw/manager.svelte.ts similarity index 74% rename from src/routes/[network]/(account)/(staking)/staking/withdraw/state.svelte.ts rename to src/routes/[network]/(account)/(staking)/staking/withdraw/manager.svelte.ts index 34d942c8..999aec1d 100644 --- a/src/routes/[network]/(account)/(staking)/staking/withdraw/state.svelte.ts +++ b/src/routes/[network]/(account)/(staking)/staking/withdraw/manager.svelte.ts @@ -11,7 +11,7 @@ import { getWithdrawableBalance } from '../utils'; -export class WithdrawState { +export class WithdrawManger { public network: NetworkState | undefined = $state(); public account: AccountState | undefined = $state(); public wharf: WharfState | undefined = $state(); @@ -29,7 +29,7 @@ export class WithdrawState { ); public withdrawable: Asset = $derived( this.account && this.network - ? getWithdrawableBalance(this.network!, this.account) + ? getWithdrawableBalance(this.network, this.account) : defaultQuantity ); public total: Asset = $derived( @@ -67,24 +67,30 @@ export class WithdrawState { } async transact() { - const actions = []; - if (this.claimable) { - actions.push( - this.network!.contracts.system.action('sellrex', { - from: this.account!.name!, - rex: this.network!.tokenToRex(this.claimable) - }) - ); - } - actions.push( - this.network!.contracts.system.action('withdraw', { - owner: this.account!.name!, - amount: this.withdrawable! - }) - ); - try { - const result = await this.wharf!.transact({ + if (!this.network || !this.account || !this.account.name || !this.wharf) { + throw new Error("Can't sign, data not ready"); + } + + const actions = []; + if (this.claimable) { + actions.push( + this.network.contracts.system.action('sellrex', { + from: this.account.name, + rex: this.network.tokenToRex(this.claimable) + }) + ); + } + if (this.total) { + actions.push( + this.network.contracts.system.action('withdraw', { + owner: this.account.name, + amount: this.total + }) + ); + } + + const result = await this.wharf.transact({ actions }); diff --git a/src/routes/[network]/api/account/[[name]]/+server.ts b/src/routes/[network]/api/account/[[name]]/+server.ts index 5d18f372..7ed52ac5 100644 --- a/src/routes/[network]/api/account/[[name]]/+server.ts +++ b/src/routes/[network]/api/account/[[name]]/+server.ts @@ -26,17 +26,19 @@ export async function GET({ fetch, params }) { Promise, Promise, Promise, + Promise, Promise ] = [ network.client.v1.chain.get_account(params.name), systemContract.table('delband').all({ scope: params.name }), systemContract.table('rexbal').get(params.name), + systemContract.table('rexfund').get(params.name), loadBalances(network, params.name, fetch) ]; try { const headers = getCacheHeaders(5); - const [account_data, delegated, rex, balances] = await Promise.all(requests); + const [account_data, delegated, rexbal, rexfund, balances] = await Promise.all(requests); // If no response from the light API, add the core liquid balance as a default if (!balances.length && chain.systemToken) { @@ -54,7 +56,8 @@ export async function GET({ fetch, params }) { account_data, balances, delegated, - rex + rex: rexbal, + rexfund: rexfund }, { headers } );