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

SIP 89 Virtual Synths #821

Closed
wants to merge 46 commits into from
Closed

SIP 89 Virtual Synths #821

wants to merge 46 commits into from

Conversation

jjgonecrypto
Copy link
Contributor

No description provided.

@jjgonecrypto
Copy link
Contributor Author

Example of running Synthetix.prod.js

image

at the same time, here was the rate on 1inch

image

# Conflicts:
#	package-lock.json
#	publish/src/commands/fork.js
# Conflicts:
#	contracts/Exchanger.sol
#	package.json
#	publish/ovm-ignore.json
#	publish/releases.json
#	test/publish/index.js
@jjgonecrypto jjgonecrypto marked this pull request as ready for review November 5, 2020 15:46
# Conflicts:
#	package-lock.json
#	package.json
}
}

function _createVirtualSynth(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the concept with ExchangerWithVirtualSynth that overrides the internal function _createVirtualSynth in the Exchanger class supposed to be that the former will be whats deployed on L1 and the normal "Exchanger" contract will be only be on OVM ?

);

_processTradingRewards(fee, originator);

_emitTrackingEvent(trackingCode, destinationCurrencyKey, amountReceived);
}

function exchangeWithVirtual(
Copy link
Contributor

@jacko125 jacko125 Nov 6, 2020

Choose a reason for hiding this comment

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

I'd split the VirtualSynth creation outside of the internal _exchange function for separation of concerns so that exchangeWithVirtual() would create a VirtualSynth after doing the exchange / conversion instead of relying on a bool flag to determine if a VirtualSynth is created within the internal _exchange function.

This could be.a limitation with the stack too deep issue instead of returning the required variables to setup a virtual synth not inside _exchange ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking this too; however the destination account needs to be known before the exchange (which is either the vSynth or the original recipient), and the vSynth needs to know the amount received after the exchange.
It's possible to do this by breaking the _exchange function up into the bits before the call to _convert, and the bits after, but I'm not sure this is any cleaner than what's here. Perhaps we can just do the exchange quantity calculation by itself and construction of the vSynth before rather than after the exchange itself, and pass these in as parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah Anton's point answers your Jacko. But doing the creation first could definitely work and might be a lot nicer. Let me look into this.

@jjgonecrypto
Copy link
Contributor Author

This needs to be moved to a PR with a new branch name to trigger the workflow-develop CI flow

Copy link
Contributor

@zyzek zyzek left a comment

Choose a reason for hiding this comment

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

Leaving several comments now, but will continue reviewing.


if (virtualSynth) {
vSynth = _createVirtualSynth(dest, recipient, amountReceived);
dest.issue(address(vSynth), amountReceived);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit of a nitpick, but a minor amount of space can be saved by reassigning the recipient address and using only one issue call, as follows:

if (virtualSynth) {
    recipient = address(_createVirtualSynth(dest, recipient, amountReceived);
}

dest.issue(recipient, amountReceived);

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternately, _createVirtualSynth on this layer could just return the recipient or zero address, and then the if statement can be removed, and the virtualSynth bool argument removed entirely in the enclosing call to _exchange by relying on the function overriding. E.g.:

vSynth = _createVirtualSynth(dest, recipient, amountReceived); // on layer 2 returns address(0);
address recipientOrSynth = vSynth == address(0) ? recipient : vSynth;
dest.issue(recipient, amountReceived);

);

_processTradingRewards(fee, originator);

_emitTrackingEvent(trackingCode, destinationCurrencyKey, amountReceived);
}

function exchangeWithVirtual(
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking this too; however the destination account needs to be known before the exchange (which is either the vSynth or the original recipient), and the vSynth needs to know the amount received after the exchange.
It's possible to do this by breaking the _exchange function up into the bits before the call to _convert, and the bits after, but I'm not sure this is any cleaner than what's here. Perhaps we can just do the exchange quantity calculation by itself and construction of the vSynth before rather than after the exchange itself, and pass these in as parameters?

emit VirtualSynthCreated(address(vSynth), address(synth), synth.currencyKey(), amount);
}

event VirtualSynthCreated(address vSynth, address synth, bytes32 currencyKey, uint amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this strictly need the currency key? One assumes it could always be recovered from the synth itself at the block this was emitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No not strictly - it just seemed like it might be better for reporting - but def not critical.

synth = _synth;
resolver = _resolver;

// Note: we can do this as Exchanger will issue this amount to us
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this comment is super clear. I guess it's saying that once the exchange that created this vSynth is complete, _synth.balanceOf(address(this)) == _amount?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep

return string(abi.encodePacked("v", synth.currencyKey()));
}

function decimals() external pure returns (uint8) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need both a public DECIMALS constant and this external decimals function? Isn't renaming DECIMALS to decimals sufficient to satisfy the ERC20 extended interface? Or am I missing some integration that expects the DECIMALS form?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just following the convention in Synth.sol but yeah, different scenario. I'll fix it up.

contracts/interfaces/IVirtualSynth.sol Show resolved Hide resolved
@jjgonecrypto
Copy link
Contributor Author

Closed for #857

@jjgonecrypto jjgonecrypto deleted the sip-89-virtual-synths branch November 7, 2020 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants