Skip to content

Commit

Permalink
feat: Smarter exchange rate updates (#1308)
Browse files Browse the repository at this point in the history
* feat: Smarter exchange rate updates

This is from a comment added in `Dataworker.ts` that also explains this PR well:

```
// There are three times that we should look to update the HubPool's liquid reserves:
    // 1. First, before we attempt to execute the HubChain PoolRebalance leaves and RelayerRefund leaves.
    //    We should see if there are new liquid reserves we need to account for before sending out these
    //    netSendAmounts.
    // 2. Second, before we attempt to execute the PoolRebalance leaves for the other chains. We should
    //    see if there are new liquid reserves we need to account for before sending out these netSendAmounts. This
    //    updated liquid reserves balance could be from previous finalizations or any amountToReturn value sent
    //    back from the Ethereum RelayerRefundLeaves.
    // 3. Third, we haven't updated the exchange rate for an L1 token on a PoolRebalanceLeaf in a while that
    //    we're going to execute, so we should batch in an update.
```

The motivation for this PR is to reduce the # of `exchangeRateCurrent()` calls to reduce dataworker costs. This PR should make it such that these calls are only batched with PoolRebalanceLeaf executions and never sent otherwise.

* refactor(test): Upgrade simple Dataworker buildRoots test to v3

This addresses a breaking change implemented in the SDK.

* lint

* increase lookback

---------

Co-authored-by: Paul <[email protected]>
  • Loading branch information
nicholaspai and pxrl authored Mar 21, 2024
1 parent ff30323 commit 3aa299e
Show file tree
Hide file tree
Showing 6 changed files with 580 additions and 194 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@across-protocol/constants-v2": "1.0.14",
"@across-protocol/contracts-v2": "2.5.3",
"@across-protocol/sdk-v2": "0.22.15",
"@across-protocol/sdk-v2": "0.22.16",
"@arbitrum/sdk": "^3.1.3",
"@consensys/linea-sdk": "^0.2.1",
"@defi-wonderland/smock": "^2.3.5",
Expand Down
4 changes: 0 additions & 4 deletions src/clients/BalanceAllocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ export class BalanceAllocator {
return this.balances[chainId][token][holder];
}

async getVirtualBalance(chainId: number, token: string, holder: string): Promise<BigNumber> {
return (await this.getBalance(chainId, token, holder)).sub(this.getUsed(chainId, token, holder));
}

getUsed(chainId: number, token: string, holder: string): BigNumber {
if (!this.used?.[chainId]?.[token]?.[holder]) {
// Note: cannot use assign because it breaks the BigNumber object.
Expand Down
Loading

0 comments on commit 3aa299e

Please sign in to comment.