-
Notifications
You must be signed in to change notification settings - Fork 2
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
[VEN-2299]: add a contract to operate token converters #3
Conversation
ed00401
to
93b043e
Compare
cd0dd1b
to
08512c8
Compare
package.json
Outdated
"@venusprotocol/protocol-reserve": "1.0.0-converters.1", | ||
"@venusprotocol/venus-protocol": "6.1.0-dev.8" | ||
"@venusprotocol/protocol-reserve": "1.3.0-dev.1", | ||
"@venusprotocol/venus-protocol": "6.1.0-dev.8", |
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.
Can we use release versions?
@venusprotocol/protocol-reserve - 1.2.0
@venusprotocol/venus-protocol - 7.0.0
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.
Not sure about protocol-reserve, but we can definitely use core v7. I'll update the other ones 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.
@@ -0,0 +1,227 @@ | |||
// @kkirka: This is a typescript file and not a JSON file because I wanted to keep |
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.
I would recommend using typechain and getting abis from packages
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.
Typechain devs say it's going to die at some point: https://github.com/dethcrypto/TypeChain?tab=readme-ov-file#soft-deprecation-notice, and I'm not sure typechain types are compatible with viem.
Actually this file is just export default <ABI JSON> as const;
, so it should be straightforward to import ABIs from packages and "decorate" them this way.
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.
Well, you can't create a const from imported JSON. It looks like HasAddressFor
isn't working as expected for this reason.
I've started working on a postinstall step where we generate EIP-712 using the wagmi/cli hardhat plugin
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.
Weird, HasAddressFor
worked for me because importing JSON yields a pretty narrow type when JSON is an object (not as narrow as const but still). Maybe it failed because governance-contracts was missing? I've added it here: 77064f9
Still, wagmi/cli sounds good, as long as you're ok with using viem
src/config/addresses.ts
Outdated
import bsctestnetCore from "@venusprotocol/venus-protocol/deployments/bsctestnet_addresses.json"; | ||
|
||
export const addresses = { | ||
// TODO: Replace hardcoded addresses with addresses from the packages |
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 something missing to complete this todo
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.
Yeah, the PR with the converters isn't merged yet, even to dev
: VenusProtocol/protocol-reserve#9
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.
readonly hex: Hex; | ||
} | ||
|
||
export const parsePath = (data: Array<Address | number>): Path => { |
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.
nit: An idea to make this safer would be accept an input like Array<[address, number, address]>
. Since each part of the path will have the same 3 parts
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.
Yeah, I didn't like Address | number
either as it doesn't really convey the shape of the expected input.
The path goes like:
[USDT, 0.5%, WBNB, 0.3%, BTC, 0.1%, XVS]
Do you propose to instead use this kind of path:
[[USDT, 0.5%, WBNB], [WBNB, 0,3%, BTC], [BTC, 0.1%, XVS]]?
It seemed too verbose to me at first, but now I think that maybe it's more readable 🤔
} | ||
|
||
get publicClient() { | ||
return this._publicClient ?? getPublicClient(this.chainName); |
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.
this._publicClient never receives an assignment. Why not set this in the constructor?
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.
Oups, I wanted some sort of laziness here, but actually did it wrong, lol 🤦 😅
The intent was sth like
get publicClient() {
if (!this._publicClient) {
this._publicClient = getPublicClient(this.chainName);
}
return this._publicClient;
}
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.
Maybe there are better ways to lazily initialize things? Some lib or a common approach (memoization, whatever)
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.
You could use the logical or assignment operator ||=
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.
} | ||
|
||
get walletClient() { | ||
return this._walletClient ?? getWalletClient(this.chainName); |
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.
this._walletClient never receives an assignment
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.
Yeah, same thing as with public client
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.
const beneficiary = this.walletClient.account.address; | ||
const chain = chains[this.chainName]; | ||
|
||
if (minIncome < 0n) { |
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.
Why would minIncome be negative?
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.
Sometimes we're willing to pay for conversions to happen, even if it's not profitable. Actually in the initial phase the incentives would be zero, so we'll probably be paying for all conversions.
): WalletClient<HttpTransport, typeof chains[ChainT], PrivateKeyAccount> => { | ||
return createWalletClient({ | ||
chain: chains[chainName], | ||
transport: http(process.env[`LIVE_NETWORK_${chainName}`]), |
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.
This env var is missing from the example
}; | ||
|
||
const readPrivateKeyFromEnv = (chainName: string): PrivateKeyAccount => { | ||
const key = process.env[`PRIVATE_KEY_${chainName}`]; |
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.
This env var is missing from the example
08512c8
to
742773f
Compare
a60912c
to
77064f9
Compare
77064f9
to
3418642
Compare
No description provided.