-
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.
- Loading branch information
Showing
11 changed files
with
230 additions
and
10 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 @@ | ||
# BSC corss greenfield SDK | ||
|
||
## Executor | ||
|
||
## MultiMessage |
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 @@ | ||
export default class MultiMessage {} |
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,103 @@ | ||
import { | ||
MsgCreatePaymentAccount, | ||
MsgDeposit, | ||
MsgDisableRefund, | ||
MsgWithdraw, | ||
} from '@bnb-chain/greenfield-cosmos-types/greenfield/payment/tx'; | ||
import { | ||
MsgCancelMigrateBucket, | ||
MsgCopyObject, | ||
MsgMigrateBucket, | ||
MsgSetBucketFlowRateLimit, | ||
MsgSetTag, | ||
MsgToggleSPAsDelegatedAgent, | ||
MsgUpdateBucketInfo, | ||
MsgUpdateGroupExtra, | ||
MsgUpdateObjectInfo, | ||
} from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx'; | ||
import { toHex } from 'viem'; | ||
import { ExecuteParams } from '../../types'; | ||
|
||
// https://github.com/bnb-chain/greenfield-contracts/blob/develop/contracts/middle-layer/GreenfieldExecutor.sol | ||
|
||
export default class ExecutorMsg { | ||
static getCreatePaymentAccountParams = (msg: MsgCreatePaymentAccount): ExecuteParams => [ | ||
1, | ||
toHex(MsgCreatePaymentAccount.encode(msg).finish()), | ||
]; | ||
|
||
static getDepositParams = (msg: MsgDeposit): ExecuteParams => [ | ||
2, | ||
toHex(MsgDeposit.encode(msg).finish()), | ||
]; | ||
|
||
static getDisableRefundParams = (msg: MsgDisableRefund): ExecuteParams => [ | ||
3, | ||
toHex(MsgDisableRefund.encode(msg).finish()), | ||
]; | ||
|
||
static getWithdrawParams = (msg: MsgWithdraw): ExecuteParams => [ | ||
4, | ||
toHex(MsgWithdraw.encode(msg).finish()), | ||
]; | ||
|
||
static getMigrateBucketParams = (msg: MsgMigrateBucket): ExecuteParams => [ | ||
5, | ||
toHex(MsgMigrateBucket.encode(msg).finish()), | ||
]; | ||
|
||
static getCancelMigrateBucketParams = (msg: MsgCancelMigrateBucket): ExecuteParams => [ | ||
6, | ||
toHex(MsgCancelMigrateBucket.encode(msg).finish()), | ||
]; | ||
|
||
static getUpdateBucketInfoParams = (msg: MsgUpdateBucketInfo): ExecuteParams => [ | ||
7, | ||
toHex(MsgUpdateBucketInfo.encode(msg).finish()), | ||
]; | ||
|
||
static getToggleSPAsDelegatedAgentParams = (msg: MsgToggleSPAsDelegatedAgent): ExecuteParams => [ | ||
8, | ||
toHex(MsgToggleSPAsDelegatedAgent.encode(msg).finish()), | ||
]; | ||
|
||
static getSetBucketFlowRateLimitParams = (msg: MsgSetBucketFlowRateLimit): ExecuteParams => [ | ||
9, | ||
toHex(MsgSetBucketFlowRateLimit.encode(msg).finish()), | ||
]; | ||
|
||
static getCopyObjectParams = (msg: MsgCopyObject): ExecuteParams => [ | ||
10, | ||
toHex(MsgCopyObject.encode(msg).finish()), | ||
]; | ||
|
||
static getUpdateObjectInfoParams = (msg: MsgUpdateObjectInfo): ExecuteParams => [ | ||
11, | ||
toHex(MsgUpdateObjectInfo.encode(msg).finish()), | ||
]; | ||
|
||
static getUpdateGroupExtraParams = (msg: MsgUpdateGroupExtra): ExecuteParams => [ | ||
12, | ||
toHex(MsgUpdateGroupExtra.encode(msg).finish()), | ||
]; | ||
|
||
static getSetTagParams = (msg: MsgSetTag): ExecuteParams => [ | ||
13, | ||
toHex(MsgSetTag.encode(msg).finish()), | ||
]; | ||
} | ||
|
||
export const splitParams = (params: ExecuteParams[]) => { | ||
const types: number[] = []; | ||
const bytes: `0x${string}`[] = []; | ||
|
||
params.forEach((p) => { | ||
types.push(p[0]); | ||
bytes.push(p[1]); | ||
}); | ||
|
||
return { | ||
types, | ||
bytes, | ||
}; | ||
}; |
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 @@ | ||
export type ExecuteParams = [number, `0x${string}`]; |
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,4 @@ | ||
ACCOUNT_PRIVATEKEY= | ||
EXECUTOR_ADDRESS= | ||
CROSSCHAIN_ADDRESS= | ||
MULTIMESSAGE_ADDRESS= |
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 @@ | ||
import dotenv from 'dotenv'; | ||
dotenv.config({ | ||
path: process.cwd() + '/tests/.env', | ||
}); | ||
|
||
export const ACCOUNT_PRIVATEKEY = (process.env.ACCOUNT_PRIVATEKEY as `0x${string}`) || '0x'; | ||
export const ExecutorAddress = (process.env.EXECUTOR_ADDRESS as `0x${string}`) || '0x'; | ||
export const CrossChainAddress = (process.env.CROSSCHAIN_ADDRESS as `0x${string}`) || '0x'; | ||
export const MultiMessageAddress = (process.env.MULTIMESSAGE_ADDRESS as `0x${string}`) || '0x'; |
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,51 @@ | ||
import { describe, expect, test } from '@jest/globals'; | ||
import ExecutorClient from '../src/executor'; | ||
import ExecutorMsg from '../src/executor/messages'; | ||
import { ACCOUNT_PRIVATEKEY, CrossChainAddress, ExecutorAddress } from './env'; | ||
import { privateKeyToAccount } from 'viem/accounts'; | ||
|
||
const executorClient = new ExecutorClient(ACCOUNT_PRIVATEKEY, ExecutorAddress, CrossChainAddress); | ||
|
||
const account = privateKeyToAccount(ACCOUNT_PRIVATEKEY); | ||
|
||
describe('deposit', () => { | ||
test('it works', async () => { | ||
const params = ExecutorMsg.getDepositParams({ | ||
creator: account.address, | ||
to: '0x00000000000000000000', | ||
amount: '0.001', | ||
}); | ||
|
||
const txHash = await executorClient.execute([params]); | ||
expect(txHash).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('createPayment', () => { | ||
test('it works', async () => { | ||
const params = ExecutorMsg.getCreatePaymentAccountParams({ | ||
creator: account.address, | ||
}); | ||
|
||
const txHash = await executorClient.execute([params]); | ||
expect(txHash).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('multiTx', () => { | ||
test('it works', async () => { | ||
const params1 = ExecutorMsg.getDepositParams({ | ||
creator: account.address, | ||
to: '0x00000000000000000000', | ||
amount: '0.001', | ||
}); | ||
|
||
const params2 = ExecutorMsg.getCreatePaymentAccountParams({ | ||
creator: account.address, | ||
}); | ||
|
||
const txHash = await executorClient.execute([params1, params2]); | ||
// console.log('txHash', txHash); | ||
expect(txHash).toBeDefined(); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.