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

feat: remove sdk network, add more exports #80

Merged
merged 8 commits into from
Feb 24, 2025
Merged

Conversation

dtbuchholz
Copy link
Collaborator

@dtbuchholz dtbuchholz commented Feb 24, 2025

  • Removes the network.ts, which was legacy code that tried to emulate rust-recall patterns
  • Removes entities/index.ts barrel file, move utils and errors into root, and export them so they're usable elsewhere
  • Moves the objects provider.ts into root
  • Fixes contract override logic
  • Alters the GatewayManager pattern to take a public client, wallet client, and contract overrides—instead of taking the RecallClient that posses these values. This required AccountManager to go through some refactoring to account for this.

Copy link

vercel bot commented Feb 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
portal ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 24, 2025 6:39pm

@@ -34,19 +30,6 @@ export const createPublicClientForChain: (
transport: http(),
});

// Creates a wallet client for the given chain with a browser wallet provider
export const walletClientFromBrowser = (
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i realized web-based wallets dont really work with the sdk wrt executing transactions, so i removed this.

we could either choose to try and make web-based wallet flows work in the sdk, or just (eventually) publish the sdkx package—and i think the latter was already the plan. maybe we call sdkx the @recallnet/web package or something.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea sounds like a good plan to eventually publish the react sdk.

@@ -84,7 +82,8 @@ export class RecallClient {
}
const chain = this.publicClient.chain;
if (!chain) throw new Error("missing chain in provided client");
this.network = config.network ?? Network.fromChain(chain);
this.subnetId = SubnetId.fromChain(chain);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

need for cross-chain flows like deposits and withdrawals. (this used to be part of the Network, which we've removed.)

const override =
contractAddress ??
overrideSupplySourceAddress ??
deployedSupplySourceAddress;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

note: this pattern appears in a couple of places. i didn't want to overhaul the AccountManager etc too much, but it's a little messy imo. i'll take another pass in a different PR on refactoring a few other pieces in #79

).read.balanceOf(args);
await reset();
return {
result: { address: addr, nonce, balance: balance.result, parentBalance },
};
}

// Approve a spender to transfer funds from the account
async approve(spender: Address, amount: bigint): Promise<Result> {
// Approve a spender to transfer funds from the account. Assumes the wallet client is on the
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

and note: i'll also handle adding docstrings to our public packages in #77

contractAddress?: Address,
publicClient: PublicClient,
walletClient: WalletClient,
contractAddress: Address,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note: this pattern is probably needed in the entities (buckets, blobs, etc) since RecallClient instantiates each entity, but then the entity itself takes a RecallClient in its constructor. It's self-referencing and not ideal, but I wanted to keep the PR small and can handle that later. will handle in #79

@@ -120,3 +132,65 @@ export const createFileHandler = (): FileHandler => ({
};
},
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

these arent "new"—we simply merged a couple of utils files into a single one

@dtbuchholz
Copy link
Collaborator Author

dtbuchholz commented Feb 24, 2025

@asutula i started to refactor some pieces from the sdk package (backward compatible with the existing RecallClient pattern, which is what's used in our agent plugins). i started with removing that weird network.ts logic which tried to recreate rust-recall patterns, and that led to some cascading changes with contract overrides and some subnet-related definitions.

i didnt want this PR to get too complicated, so i plan to do another refactor pass in the future. the tests all pass locally, so this all works for now.

once we merge this, i can merge #75, which will create a new release that accounts for the RPC changes in a989499 as well as these SDK changes

Copy link
Contributor

@asutula asutula left a comment

Choose a reason for hiding this comment

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

Nice.

@dtbuchholz dtbuchholz merged commit 2923bb8 into main Feb 24, 2025
3 checks passed
@dtbuchholz dtbuchholz deleted the dtb/refactor-sdk branch February 24, 2025 20:47
dtbuchholz pushed a commit that referenced this pull request Feb 24, 2025
# Releases
## @recallnet/chains@0.0.2

### Patch Changes

- Updated dependencies
\[[`a989499`](a989499)]:
    -   @recallnet/network-constants@0.0.2

## @recallnet/network-constants@0.0.2

### Patch Changes

- [#74](#74)
[`a989499`](a989499)
Thanks [@dtbuchholz](https://github.com/dtbuchholz)! - use stable RPC
URLs instead of versioned subdomain

## @recallnet/sdk@0.0.3

### Patch Changes

- [#80](#80)
[`2923bb8`](2923bb8)
Thanks [@dtbuchholz](https://github.com/dtbuchholz)! - remove legacy
'network' logic and use viem chains everywhere

- Updated dependencies
\[[`a989499`](a989499)]:
    -   @recallnet/network-constants@0.0.2
    -   @recallnet/chains@0.0.2
    -   @recallnet/contracts@0.0.1

Co-authored-by: textileio-machine <40302381+textileio-machine@users.noreply.github.com>
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.

2 participants