Skip to content

Commit

Permalink
improve(HubPoolClient): Remove originChain LP fee constraint (#556)
Browse files Browse the repository at this point in the history
Co-authored-by: nicholaspai <npai.nyc@gmail.com>
  • Loading branch information
pxrl and nicholaspai committed Feb 21, 2024
1 parent 351387a commit 3a3bbb1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@across-protocol/sdk-v2",
"author": "UMA Team",
"version": "0.22.1",
"version": "0.22.2",
"license": "AGPL-3.0",
"homepage": "https://docs.across.to/v/developer-docs/developers/across-sdk",
"files": [
Expand Down
42 changes: 18 additions & 24 deletions src/clients/HubPoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,6 @@ export class HubPoolClient extends BaseAbstractClient {
return { ...partialDeposit, inputToken, inputAmount };
});

// Map SpokePool token addresses to HubPool token addresses.
const hubPoolTokens: { [originToken: string]: string } = {};

// Map each HubPool token to an array of unqiue quoteTimestamps.
const utilizationTimestamps: { [hubPoolToken: string]: number[] } = {};

Expand All @@ -373,22 +370,22 @@ export class HubPoolClient extends BaseAbstractClient {

let quoteBlocks: { [quoteTimestamp: number]: number } = {};

// Map SpokePool token addresses to HubPool token addresses.
// Note: Should only be accessed via `getHubPoolToken()` or `getHubPoolTokens()`.
const hubPoolTokens: { [k: string]: string } = {};
const getHubPoolToken = (deposit: V3PartialDepositWithBlock, quoteBlockNumber: number): string => {
const tokenKey = `${deposit.originChainId}-${deposit.inputToken}`;
return (hubPoolTokens[tokenKey] ??= this.getL1TokenForDeposit({ ...deposit, quoteBlockNumber }));
};
const getHubPoolTokens = (): string[] => dedupArray(Object.values(hubPoolTokens));

// Helper to resolve the unqiue hubPoolToken & quoteTimestamp mappings.
const resolveUniqueQuoteTimestamps = (deposit: (typeof deposits)[0]): void => {
const { originChainId } = deposits[0];
const { originChainId: chainId, inputToken, quoteTimestamp } = deposit;
assert(
chainId === originChainId,
`Cannot compute bulk realizedLpFeePct for different origin chains (${chainId} != ${originChainId})`
);
const resolveUniqueQuoteTimestamps = (deposit: V3PartialDepositWithBlock): void => {
const { quoteTimestamp } = deposit;

// Resolve the HubPool token address, if it isn't already known.
const quoteBlockNumber = quoteBlocks[deposit.quoteTimestamp];
const hubPoolToken = (hubPoolTokens[inputToken] ??= this.getL1TokenForDeposit({
...deposit,
inputToken,
quoteBlockNumber,
}));
// Resolve the HubPool token address for this origin chainId/token pair, if it isn't already known.
const quoteBlockNumber = quoteBlocks[quoteTimestamp];
const hubPoolToken = getHubPoolToken(deposit, quoteBlockNumber);

// Append the quoteTimestamp for this HubPool token, if it isn't already enqueued.
utilizationTimestamps[hubPoolToken] ??= [];
Expand Down Expand Up @@ -425,15 +422,15 @@ export class HubPoolClient extends BaseAbstractClient {
};

// Helper compute the realizedLpFeePct of an individual deposit based on pre-retrieved batch data.
const computeRealizedLpFeePct = async (deposit: (typeof deposits)[0]) => {
const { originChainId, paymentChainId, inputToken, inputAmount, quoteTimestamp } = deposit;
const computeRealizedLpFeePct = async (deposit: V3PartialDepositWithBlock & { paymentChainId?: number }) => {
const { originChainId, paymentChainId, inputAmount, quoteTimestamp } = deposit;
const quoteBlock = quoteBlocks[quoteTimestamp];

if (paymentChainId === undefined) {
return { quoteBlock, realizedLpFeePct: bnZero };
}

const hubPoolToken = hubPoolTokens[inputToken];
const hubPoolToken = getHubPoolToken(deposit, quoteBlock);
const rateModel = this.configStoreClient.getRateModelForBlockNumber(
hubPoolToken,
originChainId,
Expand Down Expand Up @@ -471,10 +468,7 @@ export class HubPoolClient extends BaseAbstractClient {
// For each token / quoteBlock pair, resolve the utilisation for each quoted block.
// This can be reused for each deposit with the same HubPool token and quoteTimestamp pair.
utilization = Object.fromEntries(
await mapAsync(Object.values(hubPoolTokens), async (hubPoolToken) => [
hubPoolToken,
await resolveUtilization(hubPoolToken),
])
await mapAsync(getHubPoolTokens(), async (hubPoolToken) => [hubPoolToken, await resolveUtilization(hubPoolToken)])
);

// For each deposit, compute the post-relay HubPool utilisation independently.
Expand Down

0 comments on commit 3a3bbb1

Please sign in to comment.