Skip to content

Commit

Permalink
feat: add support for dex internal transfer, agent deposit and assign…
Browse files Browse the repository at this point in the history
…ed withdraw
  • Loading branch information
AllenLiuxt committed May 3, 2022
1 parent 5bd74e1 commit b7756cc
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 21 deletions.
5 changes: 4 additions & 1 deletion src/HTTP/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
5 changes: 4 additions & 1 deletion src/IPC/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
5 changes: 4 additions & 1 deletion src/WS/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
5 changes: 4 additions & 1 deletion src/abi/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
56 changes: 56 additions & 0 deletions src/accountBlock/account.ts
Expand Up @@ -837,6 +837,62 @@ class AccountClass {
params: [id]
});
}

dexTransfer({ destination, tokenId, amount }: {
destination: Address;
tokenId: TokenId;
amount: Uint256;
}): AccountBlock {
const err = checkParams({ destination, tokenId, amount }, [ 'destination', 'tokenId', 'amount' ]);
if (err) {
throw err;
}

return this.callContract({
abi: Contracts.DexTransfer.abi,
toAddress: Contracts.DexTransfer.contractAddress,
params: [ destination, tokenId, amount ],
tokenId
});
}

dexAgentDeposit({ beneficiary, tokenId, amount }: {
beneficiary: Address;
tokenId: TokenId;
amount: BigInt;
}): AccountBlock {
const err = checkParams({ beneficiary, tokenId, amount }, [ 'beneficiary', 'tokenId', 'amount' ]);
if (err) {
throw err;
}

return this.callContract({
abi: Contracts.DexAgentDeposit.abi,
toAddress: Contracts.DexAgentDeposit.contractAddress,
params: [beneficiary],
tokenId,
amount
});
}

dexAssignedWithdraw({ destination, tokenId, amount, label = '0x00' }: {
destination: Address;
tokenId: TokenId;
amount: Uint256;
label?: Bytes32;
}): AccountBlock {
const err = checkParams({ destination, tokenId, amount }, [ 'destination', 'tokenId', 'amount' ]);
if (err) {
throw err;
}

return this.callContract({
abi: Contracts.DexAssignedWithdraw.abi,
toAddress: Contracts.DexAssignedWithdraw.contractAddress,
params: [ destination, tokenId, amount, label ],
tokenId
});
}
}

export const Account = AccountClass;
Expand Down
5 changes: 4 additions & 1 deletion src/accountBlock/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
5 changes: 4 additions & 1 deletion src/communication/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
12 changes: 12 additions & 0 deletions src/constant/index.ts
Expand Up @@ -278,5 +278,17 @@ export const Contracts = {
DexCancelStakeById: {
contractAddress: DexFund_ContractAddress,
abi: { 'type': 'function', 'name': 'CancelStakeById', 'inputs': [{ 'name': 'id', 'type': 'bytes32' }] }
},
DexTransfer: {
contractAddress: DexFund_ContractAddress,
abi: {'type': 'function', 'name': 'Transfer', 'inputs': [ {'name': 'target', 'type': 'address'}, {'name': 'token', 'type': 'tokenId'}, {'name': 'amount', 'type': 'uint256'} ]}
},
DexAgentDeposit: {
contractAddress: DexFund_ContractAddress,
abi: {'type': 'function', 'name': 'AgentDeposit', 'inputs': [{'name': 'beneficiary', 'type': 'address'}]}
},
DexAssignedWithdraw: {
contractAddress: DexFund_ContractAddress,
abi: {'type': 'function', 'name': 'AssignedWithdraw', 'inputs': [ {'name': 'target', 'type': 'address'}, {'name': 'token', 'type': 'tokenId'}, {'name': 'amount', 'type': 'uint256'}, {'name': 'label', 'type': 'bytes'} ]}
}
};
5 changes: 4 additions & 1 deletion src/constant/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
5 changes: 4 additions & 1 deletion src/error/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
5 changes: 4 additions & 1 deletion src/keystore/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
5 changes: 4 additions & 1 deletion src/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
5 changes: 4 additions & 1 deletion src/utils/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
5 changes: 4 additions & 1 deletion src/viteAPI/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
5 changes: 4 additions & 1 deletion src/vitejs/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
5 changes: 4 additions & 1 deletion src/wallet/type.ts
Expand Up @@ -80,7 +80,10 @@ export enum TransactionType {
'DexLockVxForDividend',
'DexSwitchConfig',
'DexStakeForPrincipalSVIP',
'DexCancelStakeById'
'DexCancelStakeById',
'DexTransfer',
'DexAgentDeposit',
'DexAssignedWithdraw'
}

export declare type TokenInfo = {
Expand Down
90 changes: 83 additions & 7 deletions test/RPC/dex.js
Expand Up @@ -96,6 +96,28 @@ export default async function TestFunc() {
console.log('Step 16 OpenNewMarket. \n');
previousAccountBlock = await OpenNewMarket(previousAccountBlock);

// 7. Internal Transfer, Agent Deposit And Assigned Withdraw

await sleep(2000);

console.log('Step 17 Dex Transfer. \n');
previousAccountBlock = await InternalTransfer();

await sleep(2000);

console.log('Step 18 Agent Deposit. \n');
previousAccountBlock = await AgentDeposit(previousAccountBlock);

await sleep(2000);

console.log('Step 19 Assigned Withdraw. \n');
previousAccountBlock = await AssignedWithdraw(previousAccountBlock);

await sleep(2000);

console.log('Step 20 Assigned Withdraw with Label. \n');
previousAccountBlock = await AssignedWithdrawWithLabel(previousAccountBlock);

return null;
}

Expand Down Expand Up @@ -144,7 +166,7 @@ async function StakeForMining(previousAccountBlock) {
async function CancelStakeMining(previousAccountBlock) {
const data = await viteProvider.request('dex_getMiningStakeInfoList', address, 0, 10);
console.log('[LOG] dex_getMiningStakeInfoList', data, '\n');

if (!data || !data.stakeList || !data.stakeList.length) {
return;
}
Expand Down Expand Up @@ -205,7 +227,7 @@ async function CreateNewInviter(previousAccountBlock) {
async function BindInviteCode(previousAccountBlock) {
const code = await viteProvider.request('dex_getInviteCode', address);
console.log('[LOG] dex_getInviteCode', code, '\n');

// 1. Stake Quota For addr2
let accountBlock = tx.stakeForQuota({
beneficiaryAddress: addr2.address,
Expand All @@ -220,7 +242,7 @@ async function BindInviteCode(previousAccountBlock) {
await sleep(2000);

accountBlock = tx.send({
toAddress: addr2.address,
toAddress: addr2.address,
tokenId: Vite_TokenId,
amount: '10000000000000000000'
});
Expand Down Expand Up @@ -368,10 +390,10 @@ async function OpenNewMarket(previousAccountBlock) {
await sleep(2000);

accountBlock = tx.dexPlaceOrder({
tradeToken: tokens[0].tokenId,
quoteToken: Vite_TokenId,
side: 1,
price: '1',
tradeToken: tokens[0].tokenId,
quoteToken: Vite_TokenId,
side: 1,
price: '1',
quantity: '10'
});

Expand All @@ -380,3 +402,57 @@ async function OpenNewMarket(previousAccountBlock) {

return previousAccountBlock;
}

async function InternalTransfer(previousAccountBlock) {
const accountBlock = await tx.dexTransfer({
destination: addr2.address,
tokenId: Vite_TokenId,
amount: '100000000000000000000'
});

const result = await SendTXByPreviousAccountBlock(accountBlock, previousAccountBlock);
console.log('[LOG] Dex Transfer', result, '\n');
return result;
}

async function AgentDeposit(previousAccountBlock) {
const accountBlock = await tx.dexAgentDeposit({
beneficiary: addr2.address,
tokenId: Vite_TokenId,
amount: '300000000000000000000'
});

const result = await SendTXByPreviousAccountBlock(accountBlock, previousAccountBlock);
console.log('[LOG] Agent Deposit', result, '\n');
return result;
}

async function AssignedWithdraw(previousAccountBlock) {
const accountBlock = await tx.dexAssignedWithdraw({
destination: addr2.address,
tokenId: Vite_TokenId,
amount: '1000000000000000000'
});

const result = await SendTXByPreviousAccountBlock(accountBlock, previousAccountBlock);
console.log('[LOG] Withdraw', result, '\n');
return result;
}

async function AssignedWithdrawWithLabel(previousAccountBlock) {
const label = Buffer.concat([
Buffer.from('0bc3', 'hex'),
Buffer.from([0]),
Buffer.from('0x0000000000000000000000000000000000000001')
]).toString("hex");
const accountBlock = await tx.dexAssignedWithdraw({
destination: addr2.address,
tokenId: Vite_TokenId,
amount: '1000000000000000000',
label
});

const result = await SendTXByPreviousAccountBlock(accountBlock, previousAccountBlock);
console.log('[LOG] Assigned Withdraw', result, '\n');
return result;
}

0 comments on commit b7756cc

Please sign in to comment.