Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquidity pool withdraw operation #2379

Closed
sschiessl-bcp opened this issue Mar 12, 2021 · 5 comments
Closed

Liquidity pool withdraw operation #2379

sschiessl-bcp opened this issue Mar 12, 2021 · 5 comments
Labels

Comments

@sschiessl-bcp
Copy link

In the operation

struct liquidity_pool_withdraw_operation : public base_operation
{
struct fee_parameters_type { uint64_t fee = 5 * GRAPHENE_BLOCKCHAIN_PRECISION; };
asset fee; ///< Operation fee
account_id_type account; ///< The account who withdraws from the liquidity pool
liquidity_pool_id_type pool; ///< ID of the liquidity pool
asset share_amount; ///< The amount of the share asset to use
extensions_type extensions; ///< Unused. Reserved for future use.
account_id_type fee_payer()const { return account; }
void validate()const;
};

How do I know how much of asset_a and asset_b does the account get?

@litepresence
Copy link
Contributor

litepresence commented Mar 12, 2021

1.2.xxx
withdrew i TWENTIX
and withdrew j HONEST.USD
from liquidity pool contract 1.19.xxx
by burning an equivalent value of k TWENTIX.HUSDMM

share_amount in your transaction sent TO core is the k

you get the i and j amounts back in response FROM core as the receipt

@abitmore
Copy link
Member

@sschiessl-bcp please check

if( _share_asset_dyn_data->current_supply == op.share_amount.amount )
{
_pool_pays_a = asset( _pool->balance_a, _pool->asset_a );
_pool_pays_b = asset( _pool->balance_b, _pool->asset_b );
}
else
{
fc::uint128_t share128( op.share_amount.amount.value );
fc::uint128_t a128 = share128 * _pool->balance_a.value / _share_asset_dyn_data->current_supply.value;
FC_ASSERT( a128 < fc::uint128_t( _pool->balance_a.value ), "Internal error" );
fc::uint128_t fee_a = a128 * _pool->withdrawal_fee_percent / GRAPHENE_100_PERCENT;
FC_ASSERT( fee_a <= a128, "Withdrawal fee percent of the pool is too high" );
a128 -= fee_a;
fc::uint128_t b128 = share128 * _pool->balance_b.value / _share_asset_dyn_data->current_supply.value;
FC_ASSERT( b128 < fc::uint128_t( _pool->balance_b.value ), "Internal error" );
fc::uint128_t fee_b = b128 * _pool->withdrawal_fee_percent / GRAPHENE_100_PERCENT;
FC_ASSERT( fee_b <= b128, "Withdrawal fee percent of the pool is too high" );
b128 -= fee_b;
FC_ASSERT( a128 > 0 || b128 > 0, "Aborting due to zero outcome" );
_pool_pays_a = asset( static_cast<int64_t>( a128 ), _pool->asset_a );
_pool_pays_b = asset( static_cast<int64_t>( b128 ), _pool->asset_b );
}

@sschiessl-bcp
Copy link
Author

I can only redo that calculation if I have the pool state at the time of execution of this operation, can't I?

When doing historical analysis or simple presentation in the explorer I find that unrealistic.

Would it be possible to add more data to the op in account history?

@abitmore
Copy link
Member

abitmore commented Mar 12, 2021

@sschiessl-bcp they ARE in the account history. Please check operation_results. E.G.

locked >>> get_account_history bitcrab 20
...
56586482 2021-03-12T09:03:51 liquidity_pool_exchange_operation bitcrab fee: 1 BTS result: {"paid":[{"amount":1800000000,"asset_id":"1.3.5286"}],"received":[{"amount":500837540,"asset_id":"1.3.5925"}],"fees":[{"amount":1800000,"asset_id":"1.3.5286"},{"amount":1003682,"asset_id":"1.3.5925"},{"amount":1005693,"asset_id":"1.3.5925"}]}
56586457 2021-03-12T09:02:36 liquidity_pool_withdraw_operation bitcrab fee: 5 BTS result: {"paid":[{"amount":"80000000000","asset_id":"1.3.5921"}],"received":[{"amount":"2180064252","asset_id":"1.3.2635"},{"amount":"85479088347","asset_id":"1.3.5286"}],"fees":[{"amount":6559872,"asset_id":"1.3.2635"},{"amount":257208891,"asset_id":"1.3.5286"}]}

BTW I think what you want is #2380.

@sschiessl-bcp
Copy link
Author

@sschiessl-bcp they ARE in the account history. Please check operation_results. E.G.

locked >>> get_account_history bitcrab 20
...
56586482 2021-03-12T09:03:51 liquidity_pool_exchange_operation bitcrab fee: 1 BTS result: {"paid":[{"amount":1800000000,"asset_id":"1.3.5286"}],"received":[{"amount":500837540,"asset_id":"1.3.5925"}],"fees":[{"amount":1800000,"asset_id":"1.3.5286"},{"amount":1003682,"asset_id":"1.3.5925"},{"amount":1005693,"asset_id":"1.3.5925"}]}
56586457 2021-03-12T09:02:36 liquidity_pool_withdraw_operation bitcrab fee: 5 BTS result: {"paid":[{"amount":"80000000000","asset_id":"1.3.5921"}],"received":[{"amount":"2180064252","asset_id":"1.3.2635"},{"amount":"85479088347","asset_id":"1.3.5286"}],"fees":[{"amount":6559872,"asset_id":"1.3.2635"},{"amount":257208891,"asset_id":"1.3.5286"}]}

BTW I think what you want is #2380.

I did not look there thx a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants