-
Notifications
You must be signed in to change notification settings - Fork 9
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
adding dynamic swap fee to fx pools #1101
base: v3-canary
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 760c57c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should think about how a negative fee and APR affects our UI and if this is what we want to show
// Replica of the subgraph logic: | ||
// https://github.com/balancer/balancer-subgraph-v2/blob/60453224453bd07a0a3a22a8ad6cc26e65fd809f/src/mappings/vault.ts#L551-L564 | ||
if (swap.poolId.poolType === 'FX') { | ||
const USDC_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can we hardcode this? Isnt this different for each chain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we only compare against USDC? No other FOREX such as EURC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like all the markets are against USDC, but true that it needs to be done for other chains as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @franzns, @gmbronco, would it be possible to add a quoteToken
property on the Pool model? This new prop will hold the quote token address, whether USDC, USDC.e, or any token.
This is how we assign the quoteToken
value in our balancer-subgraph fork:
function handleNewFXPool(event: ethereum.Event, permissionless: boolean): void {
...
pool.quoteToken = getFXPoolQuoteToken(poolAddress);
...
}
function getFXPoolQuoteToken(poolAddress: Address): Bytes {
let poolContract = FXPool.bind(poolAddress);
// FXPool **always** holds the quote token in the second position
let call = poolContract.try_derivatives(BigInt.fromI32(1));
if (call.reverted) {
log.error('Failed to get quote token for FXPool: {}', [poolAddress.toHexString()]);
return stringToBytes('0x');
}
return call.value;
}
We then refer to quoteToken
instead of hardcoded USDC addresses to determine base and quote:
let isTokenInBase = tokenOutAddress === pool.quoteToken;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @franzns, @gmbronco, would it be possible to add a
quoteToken
property on the Pool model? This new prop will hold the quote token address, whether USDC, USDC.e, or any token.This is how we assign the
quoteToken
value in our balancer-subgraph fork:function handleNewFXPool(event: ethereum.Event, permissionless: boolean): void { ... pool.quoteToken = getFXPoolQuoteToken(poolAddress); ... } function getFXPoolQuoteToken(poolAddress: Address): Bytes { let poolContract = FXPool.bind(poolAddress); // FXPool **always** holds the quote token in the second position let call = poolContract.try_derivatives(BigInt.fromI32(1)); if (call.reverted) { log.error('Failed to get quote token for FXPool: {}', [poolAddress.toHexString()]); return stringToBytes('0x'); } return call.value; }
We then refer to
quoteToken
instead of hardcoded USDC addresses to determine base and quote:let isTokenInBase = tokenOutAddress === pool.quoteToken;
Yes, we should definitely do that. We already have pool type specific data where we can add the quote token. Is the quote token immutable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the quote token is immutable for FX pools
} | ||
} | ||
|
||
feeUSD = String(feeFloatUSD); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we talked about the option of a possible negative APR. Would that mean that his fee might be negative? What are the downstream effects if so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there upside / downside? i assume it's just a property of FX pools. unless you mean if some other parts of the app will need to be updated. that i'm not sure. Is there anything that depends on the apr?
Hi @gmbronco, don't we also need to update how the The code assumes a static pool swap fee, but FX pools have a dynamic swap fee
I'm thinking something like this might work:
|
Good catch. We'll need to think about that as we'll change the snapshot generation not to rely on subgraph pricing anymore. We can calculate |
Great, that makes sense to me! |
closes #802