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

Fix contract functions #516

Merged
merged 6 commits into from
Jun 27, 2023
Merged

Fix contract functions #516

merged 6 commits into from
Jun 27, 2023

Conversation

silochad
Copy link
Contributor

@silochad silochad commented Jun 27, 2023

After this PR, yarn all:build is running again. The UI is not included in that build step. A separate PR will follow to fix explicit UI issues.

  1. Updates Mow functionality to accept tokens with sensible defaults; adds support for the new mowAndMigrate function
  2. Updates withdrawDeposit(s) to have toMode parameter associated with zero withdraw upgrade

Note that MowFarmStep in the UI still calls .update directly and due to a typing issue this is compiling. A separate PR will ship to resolve (possibly disable) this.

@silochad silochad mentioned this pull request Jun 27, 2023
@silochad
Copy link
Contributor Author

Requesting retroactive review

@silochad silochad merged commit 6e1bd3d into silo-v3-ui Jun 27, 2023
@silochad silochad deleted the fix-contract-functions branch June 27, 2023 20:09
@silochad silochad requested a review from 0xalecks June 27, 2023 20:16
projects/sdk/src/lib/farm/actions/index.ts Show resolved Hide resolved
await expect(sdk.silo.mowMultiple(account, [nonWhitelistedToken])).rejects.toThrow(`${nonWhitelistedToken.symbol} is not whitelisted`);
});

it.skip("warns when single token provided", async () => {
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'll re-enable this and following tests later on when doing more testing against a local fork with the silo v3 code deployed

@@ -427,7 +454,7 @@ export class Silo {
*/
async getSeeds(_account?: string) {
const account = await Silo.sdk.getAccount(_account);
return Silo.sdk.contracts.beanstalk.balanceOfSeeds(account).then((v) => Silo.sdk.tokens.SEEDS.fromBlockchain(v));
return Silo.sdk.contracts.beanstalk.balanceOfLegacySeeds(account).then((v) => Silo.sdk.tokens.SEEDS.fromBlockchain(v));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TO DISCUSS: This now reads from the legacy balanceOfSeeds storage slot:

function balanceOfSeeds(address account) internal view returns (uint256) {
        AppStorage storage s = LibAppStorage.diamondStorage();
        return s.a[account].s.seeds;
    }

Seeds don't really exist now. A Seed previously granted 1 / 10_000 Stalk per Season. Now each token has a configuration value at s.ss[token].stalkEarnedPerSeason which defines the amount of STALK earned per BDV per Season. We should discuss UX implications

@@ -456,18 +483,25 @@ export class Silo {
*/
async getPlantableSeeds(_account?: string) {
const account = await Silo.sdk.getAccount(_account);
// TODO: this is wrong
return Silo.sdk.contracts.beanstalk.balanceOfEarnedSeeds(account).then((v) => Silo.sdk.tokens.SEEDS.fromBlockchain(v));
throw new Error("Not implemented");
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 guess this is more like "Plantable BDV" now? Since I have some BDV in Beans that I can plant which don't earn Stalk until I plant. For now, throwing an error here and can ship a separate PR to discuss.

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why this wouldn't be Plantable Seeds

projects/sdk/src/lib/silo.ts Show resolved Hide resolved
@@ -319,9 +321,12 @@ export class Tokens {

////////// Groups //////////

const siloWhitelist = [this.BEAN, this.BEAN_CRV3_LP, this.UNRIPE_BEAN, this.UNRIPE_BEAN_CRV3];
this.siloWhitelist = new Set(siloWhitelist);
this.siloWhitelistAddresses = siloWhitelist.map((t) => t.address);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found myself doing this a lot so I set it up here to optimize

Comment on lines 45 to +49
Withdraw.sdk.debug("silo.withdraw(): withdrawDeposit()", { address: token.address, season: seasons[0], amount: amounts[0] });
contractCall = Withdraw.sdk.contracts.beanstalk.withdrawDeposit(token.address, seasons[0], amounts[0]);
contractCall = Withdraw.sdk.contracts.beanstalk.withdrawDeposit(token.address, seasons[0], amounts[0], toMode);
} else {
Withdraw.sdk.debug("silo.withdraw(): withdrawDeposits()", { address: token.address, seasons: seasons, amounts: amounts });
contractCall = Withdraw.sdk.contracts.beanstalk.withdrawDeposits(token.address, seasons, amounts);
contractCall = Withdraw.sdk.contracts.beanstalk.withdrawDeposits(token.address, seasons, amounts, toMode);
Copy link
Contributor

@0xalecks 0xalecks Jun 27, 2023

Choose a reason for hiding this comment

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

Shouldn't these pass stem instead of season? Might just be a variable name change

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'll follow up with a separate PR to do an exhaustive season -> stem renaming where applicable, figured it'd be too much for the scope here; this simply gets contract funcs back up to speed

@@ -319,9 +321,12 @@ export class Tokens {

////////// Groups //////////

const siloWhitelist = [this.BEAN, this.BEAN_CRV3_LP, this.UNRIPE_BEAN, this.UNRIPE_BEAN_CRV3];
this.siloWhitelist = new Set(siloWhitelist);
this.siloWhitelistAddresses = siloWhitelist.map((t) => t.address);
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need this, an array of addresses can easily been derived from a Set of tokens where needed.
const addr = [...this.siloWhitelist].map(t => t.address)

Copy link
Contributor

Choose a reason for hiding this comment

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

Just now saw your other comment about this. You used it in two places, one of which didn't need to be an array. Not a big deal either way

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'll take a look at this again and we can revert if it's not used very often

Copy link
Contributor

Choose a reason for hiding this comment

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

Constructor parameters changed, needs to be updated here as well. Same for WithdrawDeposits (plural)
ui/src/lib/Txn/FarmSteps/silo/WithdrawFarmStep.ts, 62 and 70

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'll get to updating the UI's steps to explicitly set this value, but for now they fall back to the default INTERNAL value since that's set on the constructor. Lmk if you think this is undesirable.

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.

3 participants