Skip to content

Commit

Permalink
Merge pull request #45 from tokenbound/bj/fp-26-handling-executecall-…
Browse files Browse the repository at this point in the history
…vs-execute-with-interface-check

SDK implementation of V3
  • Loading branch information
bjfresh authored Oct 26, 2023
2 parents 08f20e6 + 84255eb commit a0221ec
Show file tree
Hide file tree
Showing 52 changed files with 3,945 additions and 7,062 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-socks-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tokenbound/sdk': minor
---

Integrate V3 registry and account implementation into SDK
8 changes: 4 additions & 4 deletions .github/workflows/on-create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
run: cd packages/sdk

- name: Install dependencies
run: npm install
run: cd packages/sdk && npm install

- name: Clean install and build 🔧
run: npm ci && npm run build
run: cd packages/sdk && npm ci && npm run build
# run: pnpm ci && pnpm build // pnpm ci not yet implemented: https://github.com/pnpm/pnpm/issues/6100

- name: Publish package on NPM 📦
run: npm publish
run: cd packages/sdk && npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
317 changes: 200 additions & 117 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/vite-wagmi-ethers-rainbowkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"util": "^0.12.5",
"viem": "^1.16.2",
"wagmi": "^1.4.3"
"viem": "^1.17.1",
"wagmi": "^1.4.5"
},
"devDependencies": {
"@types/react": "^18.2.21",
Expand Down
33 changes: 20 additions & 13 deletions examples/vite-wagmi-ethers-rainbowkit/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ import { parseUnits, getAddress } from 'viem'
import { useCallback, useEffect } from 'react'
import { useEthersSigner } from './hooks'

// const sendingTBA = '0x33D622b211C399912eC0feaaf1caFD01AFA53980'
// const recipientAddress = getAddress('0x5ed25DCC8490809215cd0632492467BEbc60B8d5')
// const ethAmount = 0.1
// const ethAmountWei = parseUnits(`${ethAmount}`, 18)

const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1'
// const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1' // Sapienz #5 on Goerli w/ V2 contract: https://tokenbound.org/assets/goerli/0x26c55c8d83d657b2fc1df497f0c991e3612bc6b2/5
const sendingTBA = '0xa2221cc0f5012D60d0bF91B840A4Ef990D44Ae39' // Sapienz #5 on Goerli w/ V3 contract
const recipientAddress = getAddress('0x9FefE8a875E7a9b0574751E191a2AF205828dEA4')
const ethAmount = 0.05
const ethAmount = 0.005
const ethAmountWei = parseUnits(`${ethAmount}`, 18)

export function App() {
Expand All @@ -32,7 +28,7 @@ export function App() {
tokenId: '9',
})

const preparedExecuteCall = await tokenboundClient.prepareExecuteCall({
const preparedExecution = await tokenboundClient.prepareExecution({
account: account,
to: account,
value: 0n,
Expand All @@ -45,7 +41,7 @@ export function App() {
})

console.log('getAccount', account)
console.log('prepareExecuteCall', preparedExecuteCall)
console.log('preparedExecution', preparedExecution)
console.log('preparedAccount', preparedAccount)

// if (signer) {
Expand All @@ -66,15 +62,25 @@ export function App() {
alert(`new account: ${createdAccount}`)
}, [tokenboundClient])

const executeCall = useCallback(async () => {
const execute = useCallback(async () => {
if (!tokenboundClient || !address) return
const executedCall = await tokenboundClient.executeCall({
const executedCall = await tokenboundClient.execute({
account: sendingTBA,
to: recipientAddress,
value: ethAmountWei,
data: '0x',
})
executedCall && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
executedCall && alert(`Executed: ${executedCall}`)
}, [tokenboundClient])

const transferETH = useCallback(async () => {
if (!tokenboundClient || !address) return
const executedTransfer = await tokenboundClient.transferETH({
account: sendingTBA,
recipientAddress,
amount: ethAmount,
})
executedTransfer && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
}, [tokenboundClient])

return (
Expand All @@ -92,8 +98,9 @@ export function App() {
maxWidth: '320px',
}}
>
<button onClick={() => executeCall()}>EXECUTE CALL</button>
<button onClick={() => execute()}>EXECUTE CALL</button>
<button onClick={() => createAccount()}>CREATE ACCOUNT</button>
<button onClick={() => transferETH()}>TRANSFER ETH</button>
</div>
)}
</>
Expand Down
4 changes: 2 additions & 2 deletions examples/vite-wagmi-ethers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"util": "^0.12.5",
"viem": "^1.16.2",
"wagmi": "^1.4.3"
"viem": "^1.17.1",
"wagmi": "^1.4.5"
},
"devDependencies": {
"@types/react": "^18.2.21",
Expand Down
77 changes: 47 additions & 30 deletions examples/vite-wagmi-ethers/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,89 @@ import { parseUnits, getAddress } from 'viem'
import { useCallback, useEffect } from 'react'
import { useEthersSigner } from './hooks'

// const sendingTBA = '0x33D622b211C399912eC0feaaf1caFD01AFA53980'
// const recipientAddress = getAddress('0x5ed25DCC8490809215cd0632492467BEbc60B8d5')
// const ethAmount = 0.1
// const ethAmountWei = parseUnits(`${ethAmount}`, 18)

const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1'
// const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1' // Sapienz #5 on Goerli w/ V2 contract: https://tokenbound.org/assets/goerli/0x26c55c8d83d657b2fc1df497f0c991e3612bc6b2/5
const sendingTBA = '0xa2221cc0f5012D60d0bF91B840A4Ef990D44Ae39' // Sapienz #5 on Goerli w/ V3 contract
const recipientAddress = getAddress('0x9FefE8a875E7a9b0574751E191a2AF205828dEA4')
const ethAmount = 0.05
const ethAmount = 0.005
const ethAmountWei = parseUnits(`${ethAmount}`, 18)

const TOKEN_CONTRACT = `0x26c55c8d83d657b2fc1df497f0c991e3612bc6b2`
const TOKEN_ID = '5'

export function App() {
const { isConnected, address } = useAccount()
const signer = useEthersSigner({ chainId: 5 })
// or useSigner() from legacy wagmi versions: const { data: signer } = useSigner()

const tokenboundClient = new TokenboundClient({ signer, chainId: 5 })
const tokenboundClient = new TokenboundClient({
signer,
chainId: 5,
})

useEffect(() => {
console.log('signer', signer)
async function testTokenboundClass() {
const account = await tokenboundClient.getAccount({
tokenContract: '0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb',
tokenId: '9',
if (!tokenboundClient) return

const tokenboundAccount = tokenboundClient.getAccount({
tokenContract: TOKEN_CONTRACT,
tokenId: TOKEN_ID,
})

const preparedExecuteCall = await tokenboundClient.prepareExecuteCall({
account: account,
to: account,
const preparedExecution = await tokenboundClient.prepareExecution({
account: tokenboundAccount,
to: recipientAddress,
value: 0n,
data: '',
})

const preparedAccount = await tokenboundClient.prepareCreateAccount({
tokenContract: '0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb',
tokenId: '1',
const preparedCreateAccount = await tokenboundClient.prepareCreateAccount({
tokenContract: TOKEN_CONTRACT,
tokenId: TOKEN_ID,
})

console.log('getAccount', account)
console.log('prepareExecuteCall', preparedExecuteCall)
console.log('preparedAccount', preparedAccount)
console.log('getAccount', tokenboundAccount)
console.log('preparedExecuteCall', preparedExecution)
console.log('preparedAccount', preparedCreateAccount)

// if (signer) {
// signer?.sendTransaction(preparedAccount)
// signer?.sendTransaction(preparedExecuteCall)
// if (address) {
// walletClient?.sendTransaction(preparedCreateAccount)
// walletClient?.sendTransaction(preparedExecuteCall)
// }
}

testTokenboundClass()
}, [tokenboundClient])
}, [])

const createAccount = useCallback(async () => {
if (!tokenboundClient || !address) return
const createdAccount = await tokenboundClient.createAccount({
tokenContract: '0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb',
tokenId: '1',
tokenContract: TOKEN_CONTRACT,
tokenId: TOKEN_ID,
})
console.log(`new account: ${createdAccount}`)
alert(`new account: ${createdAccount}`)
}, [tokenboundClient])

const executeCall = useCallback(async () => {
const execute = useCallback(async () => {
if (!tokenboundClient || !address) return
const executedCall = await tokenboundClient.executeCall({
const executedCall = await tokenboundClient.execute({
account: sendingTBA,
to: recipientAddress,
value: ethAmountWei,
data: '0x',
})
executedCall && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
executedCall && alert(`Executed: ${executedCall}`)
}, [tokenboundClient])

const transferETH = useCallback(async () => {
if (!tokenboundClient || !address) return
const executedTransfer = await tokenboundClient.transferETH({
account: sendingTBA,
recipientAddress,
amount: ethAmount,
})
executedTransfer && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
}, [tokenboundClient])

return (
Expand All @@ -91,8 +107,9 @@ export function App() {
maxWidth: '320px',
}}
>
<button onClick={() => executeCall()}>EXECUTE CALL</button>
<button onClick={() => execute()}>EXECUTE</button>
<button onClick={() => createAccount()}>CREATE ACCOUNT</button>
<button onClick={() => transferETH()}>TRANSFER ETH</button>
</div>
)}
</>
Expand Down
4 changes: 2 additions & 2 deletions examples/vite-wagmi-ethers6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"util": "^0.12.5",
"viem": "^1.16.2",
"wagmi": "^1.4.3"
"viem": "^1.17.1",
"wagmi": "^1.4.5"
},
"devDependencies": {
"@types/react": "^18.2.21",
Expand Down
33 changes: 20 additions & 13 deletions examples/vite-wagmi-ethers6/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ import { parseUnits, getAddress } from 'viem'
import { useCallback, useEffect } from 'react'
import { useEthers6Signer } from './hooks'

// const sendingTBA = '0x33D622b211C399912eC0feaaf1caFD01AFA53980'
// const recipientAddress = getAddress('0x5ed25DCC8490809215cd0632492467BEbc60B8d5')
// const ethAmount = 0.1
// const ethAmountWei = parseUnits(`${ethAmount}`, 18)

const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1'
// const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1' // Sapienz #5 on Goerli w/ V2 contract: https://tokenbound.org/assets/goerli/0x26c55c8d83d657b2fc1df497f0c991e3612bc6b2/5
const sendingTBA = '0xa2221cc0f5012D60d0bF91B840A4Ef990D44Ae39' // Sapienz #5 on Goerli w/ V3 contract
const recipientAddress = getAddress('0x9FefE8a875E7a9b0574751E191a2AF205828dEA4')
const ethAmount = 0.05
const ethAmount = 0.005
const ethAmountWei = parseUnits(`${ethAmount}`, 18)

export function App() {
Expand All @@ -34,7 +30,7 @@ export function App() {
tokenId: '9',
})

const preparedExecuteCall = await tokenboundClient.prepareExecuteCall({
const preparedExecution = await tokenboundClient.prepareExecution({
account: account,
to: account,
value: 0n,
Expand All @@ -47,7 +43,7 @@ export function App() {
})

console.log('getAccount', account)
console.log('prepareExecuteCall', preparedExecuteCall)
console.log('preparedExecution', preparedExecution)
console.log('preparedAccount', preparedAccount)

// if (signer) {
Expand All @@ -68,15 +64,25 @@ export function App() {
alert(`new account: ${createdAccount}`)
}, [tokenboundClient])

const executeCall = useCallback(async () => {
const execute = useCallback(async () => {
if (!tokenboundClient || !address) return
const executedCall = await tokenboundClient.executeCall({
const executedCall = await tokenboundClient.execute({
account: sendingTBA,
to: recipientAddress,
value: ethAmountWei,
data: '0x',
})
executedCall && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
executedCall && alert(`Executed: ${executedCall}`)
}, [tokenboundClient])

const transferETH = useCallback(async () => {
if (!tokenboundClient || !address) return
const executedTransfer = await tokenboundClient.transferETH({
account: sendingTBA,
recipientAddress,
amount: ethAmount,
})
executedTransfer && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
}, [tokenboundClient])

return (
Expand All @@ -94,8 +100,9 @@ export function App() {
maxWidth: '320px',
}}
>
<button onClick={() => executeCall()}>EXECUTE CALL</button>
<button onClick={() => execute()}>EXECUTE CALL</button>
<button onClick={() => createAccount()}>CREATE ACCOUNT</button>
<button onClick={() => transferETH()}>TRANSFER ETH</button>
</div>
)}
</>
Expand Down
4 changes: 2 additions & 2 deletions examples/vite-wagmi-viem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"util": "^0.12.5",
"viem": "^1.16.2",
"wagmi": "^1.4.3"
"viem": "^1.17.1",
"wagmi": "^1.4.5"
},
"devDependencies": {
"@types/react": "^18.2.21",
Expand Down
Loading

0 comments on commit a0221ec

Please sign in to comment.