Skip to content

Commit

Permalink
[ADHOC] chore(sdk): better support for linking, (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
sammccord authored Oct 22, 2024
1 parent 43cb33f commit 324a1c7
Show file tree
Hide file tree
Showing 26 changed files with 220 additions and 123 deletions.
6 changes: 6 additions & 0 deletions .changeset/stale-snakes-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@boostxyz/cli": minor
"@boostxyz/sdk": minor
---

better support for pnpm linking w/ env specified contracts on all implementations
2 changes: 1 addition & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const args = arg({
'--privateKey': String,
'--out': String,
'--cacheDir': String,
'--force': String,
'--force': Boolean,
'--format': String,
'-h': '--help',
'-v': '--version',
Expand Down
50 changes: 41 additions & 9 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ import {
getDeployedContractAddress,
} from '@boostxyz/sdk';
import { createConfig, deployContract } from '@wagmi/core';
import type { Hex } from 'viem';
import { http, createWalletClient } from 'viem';
import type { Client, Hex } from 'viem';
import {
http,
createTestClient,
createWalletClient,
publicActions,
walletActions,
} from 'viem';
import { type Address, privateKeyToAccount } from 'viem/accounts';
import * as _chains from 'viem/chains';
import type { Command } from '../utils';
Expand All @@ -52,6 +58,8 @@ export type DeployResult = {
ALLOWLIST_INCENTIVE_BASE: string;
CGDA_INCENTIVE_BASE: string;
ERC20_INCENTIVE_BASE: string;
ERC20_VARIABLE_INCENTIVE_BASE: string;
ERC20_VARIABLE_CRITERIA_INCENTIVE_BASE: string;
ERC1155_INCENTIVE_BASE: string;
POINTS_INCENTIVE_BASE: string;
SIGNER_VALIDATOR_BASE: string;
Expand All @@ -69,11 +77,24 @@ export const deploy: Command<DeployResult> = async function deploy(opts) {
const chain = chains[_chain];

const account = privateKeyToAccount(privateKey as Hex);
const client = createWalletClient({
account,
chain,
transport: http(),
});
let client: Client;
if (chain === chains.hardhat || chain === chains.anvil) {
client = createTestClient({
transport: http('http://127.0.0.1:8545', { retryCount: 0 }),
chain: chain,
mode: chain === chains.hardhat ? 'hardhat' : 'anvil',
account,
key: privateKey,
})
.extend(publicActions)
.extend(walletActions);
} else {
client = createWalletClient({
account,
chain,
transport: http(),
}).extend(publicActions);
}
const config = createConfig({
// biome-ignore lint/style/noNonNullAssertion: Chain is checked above, false error
chains: [chain!],
Expand All @@ -85,14 +106,25 @@ export const deploy: Command<DeployResult> = async function deploy(opts) {

const chainId = chain!.id!;

const registry = await (
const _registry = await (
new BoostRegistry({
address: null,
...options,
// biome-ignore lint/suspicious/noExplicitAny: we know what we're doing
}) as any
).deploy();

class TBoostRegistry extends BoostRegistry {
public static override addresses: Record<number, Address> = {
[chainId]: _registry.assertValidAddress(),
};
}

const registry = new TBoostRegistry({
...options,
address: _registry.assertValidAddress(),
});

const core = await (
new BoostCore({
...options,
Expand Down Expand Up @@ -305,7 +337,7 @@ export const deploy: Command<DeployResult> = async function deploy(opts) {
await registry.register(
deployable.registryType,
name,
deployable.bases[chainId],
deployable.bases[chainId]!,
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type Options = {
privateKey?: string;
out?: string;
cacheDir?: string;
force?: string;
force?: boolean;
format?: 'env' | 'json';
};

Expand Down
3 changes: 0 additions & 3 deletions packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
},
"exclude": ["dist", "build", "node_modules", "src/**/*.test.ts"],
"references": [
{
"path": "../sdk/tsconfig.build.json"
},
{
"path": "../evm"
}
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/.env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DEFAULT_CHAIN_ID=31337
VITE_TEST_NO_DEPLOY_FIXTURES=false
VITE_BOOST_CORE_ADDRESS=
VITE_BOOST_REGISTRY_ADDRESS=
VITE_CONTRACT_ACTION_BASE=
Expand All @@ -6,9 +8,11 @@ VITE_ERC721_MINT_ACTION_BASE=
VITE_SIMPLE_ALLOWLIST_BASE=
VITE_SIMPLE_DENYLIST_BASE=
VITE_VESTING_BUDGET_BASE=
VITE_MANAGED_BUDGET_BASE=
VITE_ALLOWLIST_INCENTIVE_BASE=
VITE_CGDA_INCENTIVE_BASE=
VITE_ERC20_INCENTIVE_BASE=
VITE_ERC20_VARIABLE_CRITERIA_INCENTIVE_BASE=
VITE_ERC20_VARIABLE_INCENTIVE_BASE=
VITE_ERC1155_INCENTIVE_BASE=
VITE_POINTS_INCENTIVE_BASE=
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/Actions/EventAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ export class EventAction extends DeployableTarget<
* @type {Record<number, Address>}
*/
public static override bases: Record<number, Address> = {
31337: import.meta.env.VITE_EVENT_ACTION_BASE,
...(EventActionBases as Record<number, Address>),
};
/**
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/AllowLists/SimpleAllowList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class SimpleAllowList extends DeployableTargetWithRBAC<
* @type {Record<number, Address>}
*/
public static override bases: Record<number, Address> = {
31337: import.meta.env.VITE_SIMPLE_ALLOWLIST_BASE,
...(SimpleAllowListBases as Record<number, Address>),
};
/**
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/AllowLists/SimpleDenyList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class SimpleDenyList<
* @type {Record<number, Address>}
*/
public static override bases: Record<number, Address> = {
31337: import.meta.env.VITE_SIMPLE_DENYLIST_BASE,
...(SimpleDenyListBases as Record<number, Address>),
};
/**
Expand Down
Loading

0 comments on commit 324a1c7

Please sign in to comment.