Skip to content

Commit

Permalink
Merge branch 'master' into bean-ui-uniswap-routing
Browse files Browse the repository at this point in the history
  • Loading branch information
uncoolzero authored Jan 23, 2024
2 parents 132af06 + bfc0617 commit 62eeaab
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 38 deletions.
3 changes: 3 additions & 0 deletions projects/sdk/src/lib/BeanstalkSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type Provider = ethers.providers.JsonRpcProvider;
export type Signer = ethers.Signer;
export type BeanstalkConfig = Partial<{
provider: Provider;
readProvider?: Provider;
signer: Signer;
rpcUrl: string;
subgraphUrl: string;
Expand All @@ -41,6 +42,7 @@ export class BeanstalkSDK {
public DEBUG: boolean;
public signer?: Signer;
public provider: Provider;
public readProvider?: Provider;
public providerOrSigner: Signer | Provider;
public source: DataSource;
public subgraphUrl: string;
Expand Down Expand Up @@ -116,6 +118,7 @@ export class BeanstalkSDK {
} else {
this.provider = (config.signer?.provider as Provider) ?? config.provider!;
}
this.readProvider = config.readProvider;
this.providerOrSigner = config.signer ?? config.provider!;

this.DEBUG = config.DEBUG ?? false;
Expand Down
3 changes: 3 additions & 0 deletions projects/sdk/src/lib/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
UniswapV3Router,
UniswapV3QuoterV2__factory,
UniswapV3QuoterV2,

} from "src/constants/generated";
import { BaseContract } from "ethers";

Expand All @@ -57,6 +58,7 @@ export class Contracts {
static sdk: BeanstalkSDK;

public readonly beanstalk: Beanstalk;
public readonly beanstalkRead: Beanstalk;
public readonly beanstalkPrice: BeanstalkPrice;
public readonly fertilizer: BeanstalkFertilizer;

Expand Down Expand Up @@ -100,6 +102,7 @@ export class Contracts {

// Instances
this.beanstalk = Beanstalk__factory.connect(beanstalkAddress, sdk.providerOrSigner);
this.beanstalkRead = Beanstalk__factory.connect(beanstalkAddress, sdk.readProvider ?? sdk.providerOrSigner);
this.beanstalkPrice = BeanstalkPrice__factory.connect(beanstalkPriceAddress, sdk.providerOrSigner);
this.fertilizer = BeanstalkFertilizer__factory.connect(beanstalkFertilizerAddress, sdk.providerOrSigner);

Expand Down
26 changes: 13 additions & 13 deletions projects/sdk/src/lib/events/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ export class EventManager {
const toBlock = opts.toBlock ?? "latest";

return Promise.all([
this.sdk.contracts.beanstalk.queryFilter(
this.sdk.contracts.beanstalk.filters.AddDeposit(account, opts.token?.address),
this.sdk.contracts.beanstalkRead.queryFilter(
this.sdk.contracts.beanstalkRead.filters.AddDeposit(account, opts.token?.address),
fromBlock,
toBlock
),
this.sdk.contracts.beanstalk.queryFilter(
this.sdk.contracts.beanstalk.filters.RemoveDeposit(account, opts.token?.address),
this.sdk.contracts.beanstalkRead.queryFilter(
this.sdk.contracts.beanstalkRead.filters.RemoveDeposit(account, opts.token?.address),
fromBlock,
toBlock
),
this.sdk.contracts.beanstalk.queryFilter(
this.sdk.contracts.beanstalk.filters.RemoveDeposits(account, opts.token?.address),
this.sdk.contracts.beanstalkRead.queryFilter(
this.sdk.contracts.beanstalkRead.filters.RemoveDeposits(account, opts.token?.address),
fromBlock,
toBlock
)
Expand All @@ -87,19 +87,19 @@ export class EventManager {
const toBlock = opts.toBlock ?? "latest";

return Promise.all([
this.sdk.contracts.beanstalk.queryFilter(
this.sdk.contracts.beanstalk.filters["Sow(address,uint256,uint256,uint256)"](account),
this.sdk.contracts.beanstalkRead.queryFilter(
this.sdk.contracts.beanstalkRead.filters["Sow(address,uint256,uint256,uint256)"](account),
fromBlock,
toBlock
),
this.sdk.contracts.beanstalk.queryFilter(this.sdk.contracts.beanstalk.filters.Harvest(account), fromBlock, toBlock),
this.sdk.contracts.beanstalk.queryFilter(
this.sdk.contracts.beanstalk.filters.PlotTransfer(account, null), // from
this.sdk.contracts.beanstalkRead.queryFilter(this.sdk.contracts.beanstalkRead.filters.Harvest(account), fromBlock, toBlock),
this.sdk.contracts.beanstalkRead.queryFilter(
this.sdk.contracts.beanstalkRead.filters.PlotTransfer(account, null), // from
fromBlock,
toBlock
),
this.sdk.contracts.beanstalk.queryFilter(
this.sdk.contracts.beanstalk.filters.PlotTransfer(null, account), // to
this.sdk.contracts.beanstalkRead.queryFilter(
this.sdk.contracts.beanstalkRead.filters.PlotTransfer(null, account), // to
fromBlock,
toBlock
)
Expand Down
1 change: 1 addition & 0 deletions projects/ui/src/components/App/SdkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const useBeanstalkSdkContext = () => {

const _sdk = new BeanstalkSDK({
provider: provider as any,
readProvider: provider as any,
signer: signer ?? undefined,
source: datasource,
DEBUG: IS_DEVELOPMENT_ENV,
Expand Down
25 changes: 0 additions & 25 deletions projects/ui/src/graph/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,6 @@ const mergeUsingSeasons: (keyArgs: string[]) => FieldPolicy = (keyArgs) => ({
existing.length - 1 // clamp to last index
);

console.debug('[apollo/client/read@seasons] READ:');
console.debug(
`| left: index = ${left}, season = ${readField(
'season',
existing[left]
)}`
);
console.debug(
`| right: index = ${right}, season = ${readField(
'season',
existing[right]
)}`
);
console.debug(`| existing.length = ${existing.length}`);
console.debug(
`| existing[0] = ${readField('season', existing[0])}`,
existing
);
console.debug(
`| existing[${existing.length - 1}] = ${readField(
'season',
existing[existing.length - 1]
)}`
);

// If one of the endpoints is missing, force refresh
if (!existing[left] || !existing[right]) return;

Expand Down

0 comments on commit 62eeaab

Please sign in to comment.