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: execute by proxy #58

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"starknet": "^6.11.0",
"starknet-tokenbound-sdk": "^0.3.8",
"starknet-tokenbound-sdk": "0.4.0-next.0",
"starknetkit": "^2.3.3",
"typescript": "^5.2.2",
"web-vitals": "^2.1.4"
Expand Down
8 changes: 4 additions & 4 deletions examples/sdk-starknetjs-starknetkit-starknet-react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9822,10 +9822,10 @@ standard-as-callback@^2.1.0:
resolved "https://registry.npmjs.org/standard-as-callback/-/standard-as-callback-2.1.0.tgz"
integrity sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==

starknet-tokenbound-sdk@^0.3.6:
version "0.3.6"
resolved "https://registry.npmjs.org/starknet-tokenbound-sdk/-/starknet-tokenbound-sdk-0.3.6.tgz"
integrity sha512-wVh60586aIGbegyhcK50XWL+wY495ro6quhNRUPSEImpMyfpubdn9g8Kt0m1I/qI3Mkayg12vjgAW0bEuc7YlQ==
starknet-tokenbound-sdk@0.4.0-next.0:
version "0.4.0-next.0"
resolved "https://registry.npmjs.org/starknet-tokenbound-sdk/-/starknet-tokenbound-sdk-0.4.0-next.0.tgz"
integrity sha512-HMdksGZr+2+go17ENsv+n9NTx0W+Bv5+uVjiES0zUIvZnsEMbCdSxTge1iU0sa1V5xI5j/WUyjo1TeJ7dMjmOQ==
dependencies:
"@testing-library/jest-dom" "^5.17.0"
"@testing-library/react" "^13.4.0"
Expand Down
8 changes: 4 additions & 4 deletions examples/sdk-starknetjs/package-lock.json

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

2 changes: 1 addition & 1 deletion examples/sdk-starknetjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"starknet": "^6.1.5",
"starknet-tokenbound-sdk": "^0.3.8",
"starknet-tokenbound-sdk": "0.4.0-next.3",
"typescript": "^5.2.2",
"util": "^0.12.5",
"web-vitals": "^2.1.4"
Expand Down
41 changes: 34 additions & 7 deletions examples/sdk-starknetjs/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function App() {
// replace with your address and priv key
const walletClient: WalletClient = {
address:
"0x07da6cca38Afcf430ea53581F2eFD957bCeDfF798211309812181C555978DCC3",
"0x02d904Aedff382C0D68F22444B525146ec5eA2926e271fC411845e8D9E751DE1",
privateKey: process.env.REACT_APP_PRIVATE_KEY!,
};

Expand All @@ -36,11 +36,9 @@ function App() {
"0x04F1A720BC8D441139B9C27dff5Be5a740b310c8425abAC8da72C0609014E933";

const registryAddress: string =
"0x23a6d289a1e5067d905e195056c322381a78a3bc9ab3b0480f542fad87cc580";
"0x41f87c7b00c3fb50cc7744f896f2d3438414be33912bd24f17318c9f48523a1";
const implementationAddress: string =
"0x7396dc2e3ac3b50eac9b12447d7dcc2cfddef27405c680d46d6b13dae90d804";


"0x29d2a1b11dd97289e18042502f11356133a2201dd19e716813fb01fbee9e9a4";

const options = {
walletClient: walletClient,
Expand All @@ -51,13 +49,12 @@ function App() {
jsonRPC: "https://free-rpc.nethermind.io/sepolia-juno/v0_7",
};


const tokenbound = new TokenboundClient(options);

// replace with your test NFT
const tokenContract =
"0x0000003697660a0981d734780731949ecb2b4a38d6a58fc41629ed611e8defda";
const tokenId = "50";
const tokenId = "2526";
const url = `https://sepolia.starkscan.co/contract/${account}`;

const deployAccount = async () => {
Expand Down Expand Up @@ -98,6 +95,29 @@ function App() {
}
};

const executeByProxy = async () => {
const call1: Call = {
to: "0x0388e9b2e37467b2b708ee930827177b42500f9b0e461fa3a059397dcf5a2e47",
selector:
"0x362398bec32bc0ebb411203221a35a0301193a96f317ebe5e40be9f60d15320",
calldata: [10],
};
const call2: Call = {
to: "0x0388e9b2e37467b2b708ee930827177b42500f9b0e461fa3a059397dcf5a2e47",
selector:
"0x362398bec32bc0ebb411203221a35a0301193a96f317ebe5e40be9f60d15320",
calldata: [20],
};

const proxyAddress = "0x6b4920765fec19419c6e93ae1ac43d45d2ba397ec4d0f15579cf71dd8d8d460";
try {
await tokenbound.executeByProxy(account as string, proxyAddress, [call1, call2]);
alert("txn executed successfully!");
} catch (error) {
console.log(error);
}
};

// transfer ETH to your tokenbound account and replace here
const transferERC20 = async () => {
const ETH_CONTRACT =
Expand Down Expand Up @@ -319,6 +339,13 @@ function App() {
>
execute txn
</button>
<button
onClick={executeByProxy}
className="bg-green-400 text-medium rounded-lg px-2 mr-5 py-2"
>
execute by proxy
</button>

<button
onClick={transferERC20}
className="bg-blue-800 text-medium rounded-lg px-2 mr-5 py-2"
Expand Down
8 changes: 4 additions & 4 deletions examples/sdk-starknetjs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8821,10 +8821,10 @@ stackframe@^1.3.4:
resolved "https://registry.npmjs.org/stackframe/-/stackframe-1.3.4.tgz"
integrity sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==

starknet-tokenbound-sdk@^0.3.7:
version "0.3.7"
resolved "https://registry.npmjs.org/starknet-tokenbound-sdk/-/starknet-tokenbound-sdk-0.3.7.tgz"
integrity sha512-7/jRJyQsNJyZ7JvNA5UP8+m0icxNEXTe0oZ3ja75eKhLBUwPuy11gRvMBfyZAn67GCNB5iso4fpOyebJyyG9sg==
starknet-tokenbound-sdk@0.4.0-next.3:
version "0.4.0-next.3"
resolved "https://registry.npmjs.org/starknet-tokenbound-sdk/-/starknet-tokenbound-sdk-0.4.0-next.3.tgz"
integrity sha512-Qx3lxkUHhlvq78XuBYCQru0RV2IqTAMyVsC083mhckLXIdOhXYZIqDakNl6ni3iEfGGbu6U1SZXGdIx3y+FWwQ==
dependencies:
"@testing-library/jest-dom" "^5.17.0"
"@testing-library/react" "^13.4.0"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starknet-tokenbound-sdk",
"version": "0.3.8",
"version": "0.4.0-next.3",
"description": "SDK for starknet tokenbound accounts",
"git repository": "https://github.com/Starknet-Africa-Edu/TBA-SDK/sdk",
"author": "Darlington Nnam, Ademola Kelvin",
Expand Down
18 changes: 18 additions & 0 deletions src/TokenboundClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@ export class TokenboundClient {
}
}

// @dev proxyAddress should have permissions to execute txns from the tokenbound
public async executeByProxy(tbaAddress: string, proxyAddress: string, calls: Call[]) {
const provider = getProvider(this.jsonRPC);
let call: MultiCall = {
contractAddress: proxyAddress,
entrypoint: "execute",
calldata: CallData.compile({ tbaAddress, calls }),
};

try {
const result = await this.account.execute(call);
await provider.waitForTransaction(result.transaction_hash);
return {transaction_hash: result.transaction_hash, status: true}
} catch (error) {
throw error;
}
}

public async getOwner(options: GetOwnerOptions) {
let { tbaAddress } = options;
const contract = new Contract(this.accountAbi, tbaAddress, this.account);
Expand Down