@rev-net/core-v6 0.0.69 → 0.0.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/REVDeployer.sol +39 -5
package/package.json
CHANGED
package/src/REVDeployer.sol
CHANGED
|
@@ -352,11 +352,15 @@ contract REVDeployer is ERC2771Context, IREVDeployer, IERC721Receiver {
|
|
|
352
352
|
/// @param revnetId The ID of the revnet to initialize a pool for.
|
|
353
353
|
/// @param terminalToken The terminal token to create a buyback pool for.
|
|
354
354
|
/// @param terminalTokenDecimals The number of decimals the terminal token uses.
|
|
355
|
-
/// @param
|
|
355
|
+
/// @param terminalCurrency The currency identifier of the terminal token's accounting context.
|
|
356
|
+
/// @param baseCurrency The revnet's base currency (the currency `initialIssuance` is denominated against).
|
|
357
|
+
/// @param initialIssuance The initial issuance rate (project tokens per unit of `baseCurrency`, 18 decimals).
|
|
356
358
|
function _tryInitializeBuybackPoolFor(
|
|
357
359
|
uint256 revnetId,
|
|
358
360
|
address terminalToken,
|
|
359
361
|
uint8 terminalTokenDecimals,
|
|
362
|
+
uint32 terminalCurrency,
|
|
363
|
+
uint32 baseCurrency,
|
|
360
364
|
uint112 initialIssuance
|
|
361
365
|
)
|
|
362
366
|
internal
|
|
@@ -364,7 +368,35 @@ contract REVDeployer is ERC2771Context, IREVDeployer, IERC721Receiver {
|
|
|
364
368
|
uint160 sqrtPriceX96;
|
|
365
369
|
uint256 terminalTokenUnit = 10 ** terminalTokenDecimals;
|
|
366
370
|
|
|
371
|
+
// When the terminal token's accounting currency differs from the revnet's base currency, convert the
|
|
372
|
+
// issuance rate to the terminal currency before seeding the pool. Without this, a USDC-accepting revnet
|
|
373
|
+
// with an ETH base currency seeds the pool at the ETH rate — 1000s of times off — and lets the first
|
|
374
|
+
// organic swap get sandwiched at the corrected price. When no price feed exists for the pair, skip
|
|
375
|
+
// pool initialization rather than reverting the whole deploy; the operator can wire the pool later via
|
|
376
|
+
// the buyback hook permission.
|
|
377
|
+
uint256 adjustedInitialIssuance;
|
|
367
378
|
if (initialIssuance == 0) {
|
|
379
|
+
adjustedInitialIssuance = 0;
|
|
380
|
+
} else if (terminalCurrency == baseCurrency) {
|
|
381
|
+
adjustedInitialIssuance = uint256(initialIssuance);
|
|
382
|
+
} else {
|
|
383
|
+
try CONTROLLER.PRICES()
|
|
384
|
+
.pricePerUnitOf({
|
|
385
|
+
projectId: revnetId,
|
|
386
|
+
pricingCurrency: terminalCurrency,
|
|
387
|
+
unitCurrency: baseCurrency,
|
|
388
|
+
decimals: terminalTokenDecimals
|
|
389
|
+
}) returns (
|
|
390
|
+
uint256 rate
|
|
391
|
+
) {
|
|
392
|
+
if (rate == 0) return;
|
|
393
|
+
adjustedInitialIssuance = mulDiv({x: uint256(initialIssuance), y: terminalTokenUnit, denominator: rate});
|
|
394
|
+
} catch {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (adjustedInitialIssuance == 0) {
|
|
368
400
|
sqrtPriceX96 = uint160(1 << 96);
|
|
369
401
|
} else {
|
|
370
402
|
address normalizedTerminalToken = terminalToken == JBConstants.NATIVE_TOKEN ? address(0) : terminalToken;
|
|
@@ -373,13 +405,13 @@ contract REVDeployer is ERC2771Context, IREVDeployer, IERC721Receiver {
|
|
|
373
405
|
if (projectToken == address(0) || projectToken == normalizedTerminalToken) {
|
|
374
406
|
sqrtPriceX96 = uint160(1 << 96);
|
|
375
407
|
} else if (normalizedTerminalToken < projectToken) {
|
|
376
|
-
// token0 = terminal, token1 = project → price =
|
|
408
|
+
// token0 = terminal, token1 = project → price = adjustedIssuance / terminalTokenUnit
|
|
377
409
|
sqrtPriceX96 =
|
|
378
|
-
uint160(sqrt(mulDiv({x:
|
|
410
|
+
uint160(sqrt(mulDiv({x: adjustedInitialIssuance, y: 1 << 192, denominator: terminalTokenUnit})));
|
|
379
411
|
} else {
|
|
380
|
-
// token0 = project, token1 = terminal → price = terminalTokenUnit /
|
|
412
|
+
// token0 = project, token1 = terminal → price = terminalTokenUnit / adjustedIssuance
|
|
381
413
|
sqrtPriceX96 =
|
|
382
|
-
uint160(sqrt(mulDiv({x: terminalTokenUnit, y: 1 << 192, denominator:
|
|
414
|
+
uint160(sqrt(mulDiv({x: terminalTokenUnit, y: 1 << 192, denominator: adjustedInitialIssuance})));
|
|
383
415
|
}
|
|
384
416
|
}
|
|
385
417
|
|
|
@@ -742,6 +774,8 @@ contract REVDeployer is ERC2771Context, IREVDeployer, IERC721Receiver {
|
|
|
742
774
|
revnetId: revnetId,
|
|
743
775
|
terminalToken: accountingContextsToAccept[i].token,
|
|
744
776
|
terminalTokenDecimals: accountingContextsToAccept[i].decimals,
|
|
777
|
+
terminalCurrency: accountingContextsToAccept[i].currency,
|
|
778
|
+
baseCurrency: configuration.baseCurrency,
|
|
745
779
|
initialIssuance: configuration.stageConfigurations[0].initialIssuance
|
|
746
780
|
});
|
|
747
781
|
unchecked {
|