-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: Cross BSC and Gnfd init * chore: Install deps * feat: Abi files * feat: Framework * feat: Executor * test: Test case * chore(test): Test framework * feat: Hub Abi files * chore: Hub tests * feat: MultiMessage * feat: MultiMessage module * feat: Exectuor * chore: README * Create five-chefs-lay.md * chore: Assert * feat: Support Local Account and JSONRPC Account * chore(example): Cross Example * docs: Update README * test: Delete policy case * chore: Export enum * feat: Support Callback * chore: Clean deps
- Loading branch information
Showing
45 changed files
with
9,101 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bnb-chain/bsc-cross-greenfield-sdk": patch | ||
--- | ||
|
||
Release: BSC Cross Chain SDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { BasicClientParams } from '@bnb-chain/bsc-cross-greenfield-sdk'; | ||
|
||
/** | ||
* bsc testnet | ||
*/ | ||
export const getCrossClientConfig = (address: `0x${string}`) => { | ||
const config: BasicClientParams = { | ||
chainConfig: 'testnet', | ||
accountConfig: { | ||
address, | ||
ethereumProvider: window.ethereum, | ||
}, | ||
}; | ||
|
||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { getCrossClientConfig } from '@/client/cross'; | ||
import { | ||
BUCKETHUB_ADDRESS, | ||
CROSSCHAIN_ADDRESS, | ||
EXECUTOR_ADDRESS, | ||
GROUPHUB_ADDRESS, | ||
MULTIMESSAGE_ADDRESS, | ||
OBJECTHUB_ADDRESS, | ||
PERMISSIONHUB_ADDRESS, | ||
TOKENHUB_ADDRESS, | ||
} from '@/config'; | ||
import { | ||
CrossChainClient, | ||
ExecutorClient, | ||
ExecutorMsg, | ||
MultiMessageClient, | ||
} from '@bnb-chain/bsc-cross-greenfield-sdk'; | ||
import { useAccount } from 'wagmi'; | ||
|
||
export const MultiMessage = () => { | ||
const { address } = useAccount(); | ||
|
||
return ( | ||
<div> | ||
<h3>multi message</h3> | ||
<button | ||
onClick={async () => { | ||
if (!address) return; | ||
|
||
const config = getCrossClientConfig(address); | ||
|
||
const crossChainClient = new CrossChainClient(config, CROSSCHAIN_ADDRESS); | ||
|
||
const { relayFee, minAckRelayFee } = await crossChainClient.getRelayFee(); | ||
|
||
console.log('fees: ', relayFee, minAckRelayFee); | ||
|
||
const mutliMsgClient = new MultiMessageClient(config, MULTIMESSAGE_ADDRESS, { | ||
bucketHubAddress: BUCKETHUB_ADDRESS, | ||
objectHubAddress: OBJECTHUB_ADDRESS, | ||
groupHubAddress: GROUPHUB_ADDRESS, | ||
permissionHubAddress: PERMISSIONHUB_ADDRESS, | ||
tokenHubAddress: TOKENHUB_ADDRESS, | ||
}); | ||
|
||
const args = mutliMsgClient.deleteBucket( | ||
{ | ||
id: BigInt(180013), | ||
}, | ||
{ | ||
sender: address, | ||
minAckRelayFee, | ||
relayFee, | ||
}, | ||
); | ||
|
||
const txHash = await mutliMsgClient.sendMessages([args]); | ||
|
||
console.log('txHash', txHash); | ||
}} | ||
> | ||
click | ||
</button> | ||
|
||
<h3>executor</h3> | ||
|
||
<button | ||
onClick={async () => { | ||
if (!address) return; | ||
|
||
const config = getCrossClientConfig(address); | ||
|
||
const crossChainClient = new CrossChainClient(config, CROSSCHAIN_ADDRESS); | ||
|
||
const { relayFee, minAckRelayFee } = await crossChainClient.getRelayFee(); | ||
|
||
console.log('fees: ', relayFee, minAckRelayFee); | ||
|
||
const executorClient = new ExecutorClient(config, EXECUTOR_ADDRESS); | ||
|
||
const params = ExecutorMsg.getCreatePaymentAccountParams({ | ||
creator: address, | ||
}); | ||
|
||
const txHash = await executorClient.execute([params], { relayFee }); | ||
|
||
console.log('txHash', txHash); | ||
}} | ||
> | ||
click | ||
</button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { MultiMessage } from '@/components/cross'; | ||
import { WalletInfo } from '@/components/walletInfo'; | ||
import { useIsMounted } from '@/hooks/useIsMounted'; | ||
import { useAccount } from 'wagmi'; | ||
|
||
export default function Cross() { | ||
const isMounted = useIsMounted(); | ||
const { isConnected } = useAccount(); | ||
|
||
if (!isMounted) return null; | ||
|
||
return ( | ||
<div style={{ padding: 10 }}> | ||
<WalletInfo /> | ||
|
||
<hr style={{ margin: '10px 0' }} /> | ||
|
||
{isConnected && ( | ||
<> | ||
<h2>Cross</h2> | ||
|
||
<MultiMessage /> | ||
</> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
# BSC corss greenfield SDK | ||
|
||
## Install | ||
|
||
```bash | ||
npm install @bnb-chain/bsc-cross-greenfield-sdk | ||
``` | ||
|
||
## Usage Examples | ||
|
||
### Local Account | ||
|
||
> A Local Account performs signing of transactions & messages with a private key before executing a method over JSON-RPC. | ||
#### Executor | ||
|
||
```js | ||
import {CrossChainClient, ExecutorClient, ExecutorMsg} from '@bnb-chain/bsc-cross-greenfield-sdk' | ||
import {privateKeyToAccount} from 'viem' | ||
|
||
const privateKey = ... | ||
const CrossChainAddress = ... | ||
const ExecutorAddress = ... | ||
|
||
const account = privateKeyToAccount(privateKey); | ||
const config = { | ||
// 'testnet' | 'mainnet' | ||
chainConfig: 'testnet', | ||
accountConfig: { | ||
privateKey: privateKey, | ||
}, | ||
}; | ||
|
||
const crossChainClient = new CrossChainClient(config, CrossChainAddress); | ||
const executorClient = new ExecutorClient(config, ExecutorAddress); | ||
|
||
;(async => { | ||
const { relayFee } = await crossChainClient.getRelayFee(); | ||
const params = ExecutorMsg.getCreatePaymentAccountParams({ | ||
creator: account.address, | ||
}); | ||
|
||
const txHash = await executorClient.execute([params], { relayFee }); | ||
})() | ||
``` | ||
|
||
#### MultiMessage | ||
|
||
```js | ||
import {CrossChainClient, MultiMessageClient} from '@bnb-chain/bsc-cross-greenfield-sdk' | ||
|
||
const privateKey = ... | ||
const CrossChainAddress = ... | ||
const MultiMessageAddress = ... | ||
|
||
const account = privateKeyToAccount(privateKey); | ||
|
||
const crossChainClient = new CrossChainClient(CrossChainAddress); | ||
const multiMsgClient = new MultiMessageClient(ACCOUNT_PRIVATEKEY, MultiMessageAddress, { | ||
bucketHubAddress: ..., | ||
objectHubAddress: ..., | ||
groupHubAddress: ..., | ||
permissionHubAddress: ..., | ||
tokenHubAddress: ..., | ||
}); | ||
|
||
;(async => { | ||
const { relayFee, minAckRelayFee } = await crossChainClient.getRelayFee(); | ||
|
||
const args = mutliMsgClient.createBucket( | ||
{ | ||
name: 'testBucketName', | ||
chargedReadQuota: BigInt(11), | ||
creator: account.address, | ||
visibility: 1, | ||
paymentAddress: account.address, | ||
primarySpAddress: '0xd142052d8c0881fc7485c1270c3510bc442e05dd', | ||
primarySpApprovalExpiredHeight: BigInt(0), | ||
globalVirtualGroupFamilyId: 1, | ||
primarySpSignature: '0x', | ||
extraData: '0x', | ||
}, | ||
{ | ||
sender: account.address, | ||
minAckRelayFee, | ||
relayFee, | ||
}, | ||
); | ||
|
||
const txHash = await mutliMsgClient.sendMessages([args]); | ||
})() | ||
``` | ||
|
||
### JSON-RPC Account | ||
|
||
> A JSON-RPC Account defers signing of transactions & messages to the target Wallet over JSON-RPC. An example could be sending a transaction via a Browser Extension Wallet (e.g. MetaMask) with the `window.ethereum` Provider. | ||
[Example](https://github.com/bnb-chain/greenfield-js-sdk/blob/60bdc913abd9bbcf1053d01259d006744b4da6d5/examples/nextjs/src/components/cross/index.tsx) | ||
|
||
#### Executor | ||
|
||
```js | ||
import { CrossChainClient, ExecutorClient, ExecutorMsg} from '@bnb-chain/bsc-cross-greenfield-sdk'; | ||
|
||
const CROSSCHAIN_ADDRESS = ... | ||
|
||
const config = { | ||
chainConfig: 'testnet', | ||
accountConfig: { | ||
address, | ||
ethereumProvider: window.ethereum, | ||
}, | ||
}; | ||
|
||
const crossChainClient = new CrossChainClient(config, CROSSCHAIN_ADDRESS); | ||
const executorClient = new ExecutorClient(config, EXECUTOR_ADDRESS); | ||
|
||
;(async () => { | ||
const { relayFee, minAckRelayFee } = await crossChainClient.getRelayFee(); | ||
|
||
const params = ExecutorMsg.getCreatePaymentAccountParams({ | ||
creator: address, | ||
}); | ||
|
||
const txHash = await executorClient.execute([params], { relayFee }); | ||
})() | ||
``` | ||
|
||
#### MultiMessage | ||
|
||
```js | ||
import { | ||
CrossChainClient, | ||
MultiMessageClient, | ||
} from '@bnb-chain/bsc-cross-greenfield-sdk'; | ||
|
||
const crossChainClient = new CrossChainClient(config, CROSSCHAIN_ADDRESS); | ||
|
||
const mutliMsgClient = new MultiMessageClient(config, MULTIMESSAGE_ADDRESS, { | ||
bucketHubAddress: ..., | ||
objectHubAddress: ..., | ||
groupHubAddress: ..., | ||
permissionHubAddress: ..., | ||
tokenHubAddress: ..., | ||
}); | ||
|
||
const args = mutliMsgClient.deleteBucket( | ||
{ | ||
id: BigInt(180013), | ||
}, | ||
{ | ||
sender: address, | ||
minAckRelayFee, | ||
relayFee, | ||
}, | ||
); | ||
|
||
;(async () => { | ||
const { relayFee, minAckRelayFee } = await crossChainClient.getRelayFee(); | ||
|
||
const txHash = await mutliMsgClient.sendMessages([args]); | ||
})() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"target": "ES2015", | ||
"module": "ESNext", | ||
"outDir": "../dist/cjs/", | ||
"esModuleInterop": true, | ||
"moduleResolution": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"module": "ES2020", | ||
"outDir": "../dist/esm/", | ||
"moduleResolution": "node" | ||
} | ||
} |
Oops, something went wrong.