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

Deposit history #427

Merged
merged 26 commits into from
May 29, 2024
Merged

Deposit history #427

merged 26 commits into from
May 29, 2024

Conversation

r-czajkowski
Copy link
Contributor

@r-czajkowski r-czajkowski commented May 15, 2024

Depends on: #371

This PR adds support for fetching the deposits in SDK. We must fetch data from both sources tbtc API and Acre subgraph because the tbtc API includes additional queued deposits - this means they have not yet been initialized or finalized. The subgraph only indexes initialized and finalized deposits, so we need to combine them.

@r-czajkowski r-czajkowski added 🎨 dApp dApp 🔌 SDK TypeScript SDK Library labels May 15, 2024
@r-czajkowski r-czajkowski requested a review from kkosiorowska May 15, 2024 16:29
return responseData.map((deposit) => ({
...deposit,
initialAmount: BigInt(deposit.initialAmount),
depositKey: ethers.solidityPackedKeccak256(
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we override it only if it's empty? I know the Deposit type returned by the API doesn't contain the depositKey property. Maybe we shouldn't define a generic Deposit type but return the same set of properties the API returns and later in src/modules/tbtc/Tbtc.ts we would calculate the depositKey and convert the initial amount type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

)

const amount = toSatoshi(
depositFromSubgraph?.amount ?? deposit.initialAmount,
Copy link
Member

Choose a reason for hiding this comment

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

As per conversation let's use the initial amount, regardless of the deposit state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it looks like we do not need the subgraph integration. At least for now, right?

Copy link
Member

Choose a reason for hiding this comment

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

We don't need it for now, but since you already implemented it maybe it would be worth keeping it. It gives us the possibility to fetch deposits from the chain, in case they are missed in the tBTC API for any reason (e.g. they were created not using the tBTC API).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(e.g. they were created not using the tBTC API).

So IMO in that case we should get the amount from subgraph otherwise it will be null. I will update getDepositsByOwner from AcreSubgraphApi and add all the "amount" fields, and here we will always use initialAmount but from different sources.

@@ -11,7 +11,7 @@ import { IEthereumSignerCompatibleWithEthersV5 as EthereumSignerCompatibleWithEt
* Represents the tBTC module.
*/
export default class Tbtc {
readonly #tbtcApi: TbtcApi
public readonly tbtcApi: TbtcApi
Copy link
Member

Choose a reason for hiding this comment

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

Instead of exposing this property could we define a getDepositsByOwner class that would fetch the data from tBTC API and convert the types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@r-czajkowski r-czajkowski self-assigned this May 16, 2024
r-czajkowski and others added 12 commits May 22, 2024 13:24
We are going to use the `tbtcApi` in other modules.
And expose the `getDepositsByOwner` function that returns all deposits
for a given depositor.
Expose the `getDepositsByOwner` function that returns all deposits for a
given deposit. The main difference between this function and from
`AcreSubgraphApi` class is that tbtc api stores queued deposits - this
means they have not yet been initialized or finalized. Subgraph only
indexes initialized or finalized deposits.
Add function that returns all deposits - `queued`, `initialized` and
`finalized` for a given depositor. Depositor address is created besed on
the bitcoin address returned by `BitcoinProvider`.
Add Acre subgraph api - used to fetch deposits data.
To fetch deposit activities for a given user.
Return amount in satoshi precision.
Remove "sign message first" requirement. We want to skip the signing
message step since there is a bug with this feature in Ledger Live
Wallet API.
Insted of exposing the `tbtcApi` property we define `getDepositsByOwner`
function that fetches the data from tBTC API and converts types.
Add unit tests for `getDepositsByOwner` method.
Also here we update the `getDepositsByOwner` from `AcreSubgraphApi` -
add the `amountToDeposit` and `initialAmount` fields and we should use
the initial amount regardless of the deposit state.
@r-czajkowski r-czajkowski requested a review from nkuba May 22, 2024 14:52
@r-czajkowski r-czajkowski marked this pull request as ready for review May 23, 2024 11:56
Copy link
Contributor

@kkosiorowska kkosiorowska left a comment

Choose a reason for hiding this comment

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

Overall, it looks good. I left a few small comments.

dapp/src/types/activity.ts Outdated Show resolved Hide resolved
dapp/src/utils/subgraphAPI.ts Show resolved Hide resolved
/**
* Represents the deposit data.
*/
export type Deposit = {
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can see, we define the Deposit type 3 times. We export only one type but I would consider changing the names of these types a bit. Because there may be confusion when we want to export some more types. Additionally, we mix these types a little with each other. See below.

The getDeposits function returns a Deposit type just like this.#acreSubgraphApi.getDepositsByOwner. But these are different types. This is not a blocking comment, just flagging.

Screenshot 2024-05-28 at 10 03 18

Copy link
Member

@nkuba nkuba May 28, 2024

Choose a reason for hiding this comment

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

Since we export the Deposit type just once it shouldn't be too confusing externally. But I agree we need to sort this out sooner rather than later. We plan to refactor the SDK to reduce confusion and simplify usage and development.

sdk/test/lib/api/acre-subgraph.test.ts Outdated Show resolved Hide resolved
sdk/src/modules/staking/index.ts Outdated Show resolved Hide resolved
We need to return the `timestamp` (when the deposit was created) - we
display the time for the activity in the transaction table.
To avoid code duplication and reuse it in unit tests.
We moved the subgraph integration to the SDK so the
`VITE_ACRE_SUBGRAPH_URL` is no longer needed.
Make the `type` field required and update the `status` field to
`pending` | `completed`. The activity is also a withdrawal so statuses
must be generic and the `DepositStatus` type was too specific and it
won't fit for the withdrawals.

Here we also set correct values in the `useFetchDeposits` hook.
@r-czajkowski r-czajkowski requested a review from kkosiorowska May 29, 2024 09:57
We changed the `status` type from `DepositStatus` to `pending |
completed`. Here we use correct equality to check whether the deposit
has completed status.
Base automatically changed from bitcoin-native-experience to main May 29, 2024 11:37
kkosiorowska
kkosiorowska previously approved these changes May 29, 2024
Copy link
Contributor

@kkosiorowska kkosiorowska left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 Let's resolve conflicts and merge it.

dapp/src/hooks/sdk/useInitDataFromSdk.ts Show resolved Hide resolved
Copy link

netlify bot commented May 29, 2024

Deploy Preview for acre-dapp-testnet ready!

Name Link
🔨 Latest commit ff637eb
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp-testnet/deploys/66571de06ce73d000823a24a
😎 Deploy Preview https://deploy-preview-427--acre-dapp-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kkosiorowska kkosiorowska merged commit 0f38dd2 into main May 29, 2024
24 checks passed
@kkosiorowska kkosiorowska deleted the deposit-history branch May 29, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎨 dApp dApp 🔌 SDK TypeScript SDK Library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants