Skip to content

Commit

Permalink
Merge pull request #28 from Darlington02/develop
Browse files Browse the repository at this point in the history
feat: Implement TBAStarknetWindowObject
  • Loading branch information
Darlington02 authored Feb 16, 2024
2 parents 104b3ba + e542de9 commit 4b49e5b
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 23 deletions.
26 changes: 25 additions & 1 deletion connector/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"get-starknet-core": "^3.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
Expand Down Expand Up @@ -43,6 +44,7 @@
"starknet": "^6.0.0",
"typescript": "^5.2.2",
"vite": "^4.4.9",
"vite-plugin-dts": "^3.5.1"
"vite-plugin-dts": "^3.5.1",
"zod": "^3.22.4"
}
}
38 changes: 35 additions & 3 deletions connector/src/connector/windowObject/TBAStarknetWindowObject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
// modified and updated version of the starknetWindowObject, important links below:
import type {
ConnectedStarknetWindowObject,
StarknetWindowObject
} from "get-starknet-core";

// https://github.com/argentlabs/starknetkit/blob/develop/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts
// https://github.com/starknet-io/get-starknet/blob/master/packages/core/src/StarknetWindowObject.ts#L75
import type {
AccountInterface,
ProviderInterface
} from "starknet";

import { TokenboundAccount } from "./tokenboundAccount";

export async function updateStarknetWindowObject(
wallet: StarknetWindowObject,
provider: ProviderInterface,
tokenboundAddress: string,
parentAccount: AccountInterface
): Promise<ConnectedStarknetWindowObject> {
const chainId = await provider.getChainId()

const valuesToAssign: Pick<
ConnectedStarknetWindowObject, "id" | "name" | "icon" | "version" | "isConnected" | "chainId" | "selectedAddress" | "account" | "provider"
> = {
id: "TBA",
name: "Tokenbound Account",
icon: "https://tokenbound.org/_next/image?url=%2Ftb-mark.svg&w=96&q=75",
version: "1.0.0",
isConnected: true,
chainId,
selectedAddress: tokenboundAddress,
account: new TokenboundAccount(provider, tokenboundAddress, parentAccount),
provider
}

return Object.assign(wallet, valuesToAssign)
}
4 changes: 0 additions & 4 deletions connector/src/connector/windowObject/modifiedAccount.ts

This file was deleted.

62 changes: 62 additions & 0 deletions connector/src/connector/windowObject/tokenboundAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
Signature,
Account,
AccountInterface,
ProviderInterface,
SignerInterface,
Call,
CallData,
} from "starknet";

class UnimplementedSigner implements SignerInterface {
async getPubKey(): Promise<string> {
throw new Error("Method not implemented");
}

async signMessage(): Promise<Signature> {
throw new Error("Method not implemented");
}

async signTransaction(): Promise<Signature> {
throw new Error("Method not implemented");
}

async signDeclareTransaction(): Promise<Signature> {
throw new Error("Method not implemented");
}

async signDeployAccountTransaction(): Promise<Signature> {
throw new Error("Method not implemented");
}
}

export class TokenboundAccount extends Account implements AccountInterface {
public signer = new UnimplementedSigner();

constructor(
provider: ProviderInterface,
public address: string,
public parentAccount: AccountInterface
) {
super(provider, address, new UnimplementedSigner);
}

override execute = async (
calls: Call[]
) => {
try {
let call: Call = {
contractAddress: this.address,
entrypoint: '__execute__',
calldata: CallData.compile({
calls
})
}
return await this.parentAccount.execute(call);
}
catch(error) {
console.log(error);
throw new Error("Error while executing a transaction");
}
}
}
10 changes: 9 additions & 1 deletion connector/src/modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
// modal UI goes here
import React from "react";

function index() {
return (
<div>Modal goes in here</div>
)
}

export default index
2 changes: 1 addition & 1 deletion connector/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, 'src/index.ts'),
entry: resolve(__dirname, 'src/modal/index.ts'),
name: 'tokenbound-connector',
// the proper extensions will be added
fileName: 'starknet-tokenbound-connector',
Expand Down
31 changes: 21 additions & 10 deletions sdk/src/TokenboundClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
import { AccountInterface, Contract, BigNumberish, CallData, cairo, TypedData } from "starknet"
import {
AccountInterface,
Contract,
BigNumberish,
CallData,
cairo
} from "starknet"

import {
LockOptions,
Call,
CreateAccountOptions,
GetAccountOptions,
TokenboundClientOptions,
GetOwnerOptions,
ERC20TransferOptions,
NFTTransferOptions,
MultiCall
} from "./types/TokenboundClient"

import { accountClient } from "./utils/account"
import { LockOptions, Call, CreateAccountOptions, GetAccountOptions, TokenboundClientOptions, GetOwnerOptions, ERC20TransferOptions, NFTTransferOptions, MultiCall } from "./types/TokenboundClient"
import { getProvider } from "./utils/provider"

import registryAbi from "./abis/registry.abi.json"
Expand Down Expand Up @@ -204,12 +222,5 @@ export class TokenboundClient {
}
}

public async signMessage(typedData: TypedData) {
try {
return await this.account.signMessage(typedData)
}
catch (error) {
throw error
}
}
// implement signMessage method
}
14 changes: 13 additions & 1 deletion sdk/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
export type { TokenboundClientOptions, GetAccountOptions, CreateAccountOptions, AccountStatus, Call, LockOptions, LockStatus, GetOwnerOptions, ERC20TransferOptions, NFTTransferOptions } from "./TokenboundClient"
export type {
TokenboundClientOptions,
GetAccountOptions,
CreateAccountOptions,
AccountStatus,
Call,
LockOptions,
LockStatus,
GetOwnerOptions,
ERC20TransferOptions,
NFTTransferOptions
} from "./TokenboundClient"

export type { WalletClient } from "./walletClient"
5 changes: 4 additions & 1 deletion sdk/src/utils/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Account } from "starknet"
import { getProvider } from "./provider"
import { WalletClient } from "../types/walletClient"

export function accountClient(jsonRPC: string, walletClient?: WalletClient): Account {
export function accountClient(
jsonRPC: string,
walletClient?: WalletClient
): Account {
const account = new Account(getProvider(jsonRPC), walletClient!.address, walletClient!.privateKey)
return account
}

0 comments on commit 4b49e5b

Please sign in to comment.