Skip to content

Commit

Permalink
Fix the issue in TokenWrapper contract (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
duguorong009 authored Aug 15, 2022
1 parent 24cd666 commit 5656499
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 31 deletions.
32 changes: 19 additions & 13 deletions contracts/tokenwrapper/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn instantiate(
fee_recipient,
fee_percentage,
native_token_denom: msg.native_token_denom,
is_native_allowed: msg.is_native_allowed != 0,
is_native_allowed: msg.is_native_allowed,
wrapping_limit: msg.wrapping_limit,
proposal_nonce: 0_u64,
},
Expand Down Expand Up @@ -253,10 +253,13 @@ fn wrap_native(
}

// send "fee" to fee_recipient
let msgs: Vec<CosmosMsg> = vec![CosmosMsg::Bank(BankMsg::Send {
to_address: config.fee_recipient.to_string(),
amount: coins(cost_to_wrap.u128(), config.native_token_denom),
})];
let mut msgs: Vec<CosmosMsg> = vec![];
if !cost_to_wrap.is_zero() {
msgs.push(CosmosMsg::Bank(BankMsg::Send {
to_address: config.fee_recipient.to_string(),
amount: coins(cost_to_wrap.u128(), config.native_token_denom),
}));
}

Ok(Response::new().add_messages(msgs).add_attributes(vec![
attr("action", "wrap_native"),
Expand Down Expand Up @@ -424,14 +427,17 @@ fn wrap_cw20(
}

// Send the "fee" to "fee_recipient".
let msgs: Vec<CosmosMsg> = vec![CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: cw20_address.to_string(),
funds: vec![],
msg: to_binary(&Cw20ExecuteMsg::Transfer {
recipient: config.fee_recipient.to_string(),
amount: cost_to_wrap,
})?,
})];
let mut msgs: Vec<CosmosMsg> = vec![];
if !cost_to_wrap.is_zero() {
msgs.push(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: cw20_address.to_string(),
funds: vec![],
msg: to_binary(&Cw20ExecuteMsg::Transfer {
recipient: config.fee_recipient.to_string(),
amount: cost_to_wrap,
})?,
}));
}

Ok(Response::new().add_messages(msgs).add_attributes(vec![
attr("action", "wrap_cw20"),
Expand Down
2 changes: 1 addition & 1 deletion contracts/tokenwrapper/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const FEE_PERCENTAGE: u8 = 1_u8;
const NATIVE_TOKEN_DENOM: &str = "uusd";
const CW20_TOKEN: &str = "cw20_token";
const WRAPPING_LIMIT: u128 = 5000000;
const IS_NATIVE_ALLOWED: u32 = 1;
const IS_NATIVE_ALLOWED: bool = true;

fn init_tokenwrapper(coins: Vec<Coin>) -> OwnedDeps<MockStorage, MockApi, MockQuerier> {
let mut deps = mock_dependencies_with_balance(&coins);
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol_cosmwasm/src/token_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct InstantiateMsg {
/// native token denom string to be wrapped
pub native_token_denom: String,
/// flag of is_native_allowed
pub is_native_allowed: u32,
pub is_native_allowed: bool,
/// wrapping limit
pub wrapping_limit: Uint128,
}
Expand Down
37 changes: 37 additions & 0 deletions test-scripts/src/config/localjunoConstants.ts.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,42 @@ export const localjuno = {
anchor: "juno...",
vanchor: "juno...",
mixer: "juno...",
treasuryHandler: "juno...",
treasury: "juno...",
},

contractsConsts: {
chain_id: "3751615234", // "testing"

// Test Cw20 token
cw20TokenName: "ABC_TOKEN",
cw20TokenSymbol: "ABCT",
decimals: 6,

// "SignatureBridge"
testPubKey: [],
testPrivKey: "0x...",

// "TokenWrapper"
tokenWrapperTokenName: "Webb_Wrap_Token",
tokenWrapperTokenSymbol: "WWRT",

feePercentage: 0,
nativeTokenDenom: "ucosm",
isNativeAllowed: true,
tokenWrapperWrappingLimit: "1000000",


// "TokenWrapperHandler"

// "Anchor", "VAnchor" & "Mixer"
maxEdges: 2,
levels: 30,
depositSize: "1000000",

maxDepositAmt: "1000000",
minWithdrawAmt: "0",
maxExtAmt: "1000000",
maxFee: "1000000",
}
};
2 changes: 1 addition & 1 deletion test-scripts/src/environments/localjuno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function initialize() {
treasury = config.contracts.treasury;
treasuryHandler = config.contracts.treasuryHandler;

console.log(`Use ${chalk.cyan(cw20)} as Cw20(AUTO) token`);
console.log(`Use ${chalk.cyan(cw20)} as Cw20(ABCT) token`);
console.log(`Use ${chalk.cyan(signatureBridge)} as SignatureBridge`);
console.log(`Use ${chalk.cyan(tokenWrapper)} as TokenWrapper`);
console.log(`Use ${chalk.cyan(tokenWrapperHandler)} as TokenWrapperHandler`);
Expand Down
2 changes: 1 addition & 1 deletion test-scripts/src/environments/testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function initialize() {
treasury = config.contracts.treasury;
treasury = config.contracts.treasuryHandler;

console.log(`Use ${chalk.cyan(cw20)} as Cw20(AUTO) token`);
console.log(`Use ${chalk.cyan(cw20)} as Cw20(ABCT) token`);
console.log(`Use ${chalk.cyan(signatureBridge)} as SignatureBridge`);
console.log(`Use ${chalk.cyan(tokenWrapper)} as TokenWrapper`);
console.log(`Use ${chalk.cyan(tokenWrapperHandler)} as TokenWrapperHandler`);
Expand Down
12 changes: 6 additions & 6 deletions test-scripts/src/processes/setup/testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export async function setupContracts(
wallet3 = wallets.wallet3;

// Send some test tokens to test wallets
await junod.sendTokens(localjuno.addresses.wallet1, localjuno.addresses.wallet2, [coin("100000000", "ucosm"), coin("10000000", "ujunox")], "auto");
await junod.sendTokens(localjuno.addresses.wallet1, localjuno.addresses.wallet3, [coin("100000000", "ucosm"), coin("10000000", "ujunox")], "auto");
await junod.sendTokens(localjuno.addresses.wallet1, localjuno.addresses.wallet2, [coin("10000000", "ucosm"), coin("1000000", "ujunox")], "auto");
await junod.sendTokens(localjuno.addresses.wallet1, localjuno.addresses.wallet3, [coin("10000000", "ucosm"), coin("1000000", "ujunox")], "auto");

await setup(junod, wallet1);

Expand Down Expand Up @@ -149,9 +149,9 @@ async function setup(
// Step 2. Instantiate contracts

// CW20 token
process.stdout.write("Instantiating CW20(AUTO) token contract");
process.stdout.write("Instantiating CW20(ABC) token contract");

const autoTokenResult = await instantiateContract(
const cw20TokenResult = await instantiateContract(
junod,
wallet1,
wallet1,
Expand All @@ -176,7 +176,7 @@ async function setup(
]
}
);
cw20 = autoTokenResult.contractAddress;
cw20 = cw20TokenResult.contractAddress;
console.log(chalk.green(" Done!"), `${chalk.blue("contractAddress")}=${cw20}`);


Expand Down Expand Up @@ -222,7 +222,7 @@ async function setup(
);
tokenWrapper = tokenWrapperResult.contractAddress;

// Register Cw20(AUTO) token in "TokenWrapper"
// Register Cw20(ABCT) token in "TokenWrapper"
await junod.execute(localjuno.addresses.wallet1, tokenWrapper, {
add_cw20_token_addr: {
token: cw20,
Expand Down
6 changes: 3 additions & 3 deletions test-scripts/src/processes/tests/anchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export async function testAnchorInitialize(
// TEST: Anchor
//
// SCENARIO:
// 1. Wallet3 "wrap"s some CW20 token(AUTO) in anchor
// 1. Wallet3 "wrap"s some CW20 token(ABCT) in anchor
// ------------------------------------------------
export async function testAnchorWrapCw20(
junod: SigningCosmWasmClient,
Expand All @@ -239,7 +239,7 @@ export async function testAnchorInitialize(
wallet3: DirectSecp256k1HdWallet,
auto_amount: string,
): Promise<void> {
process.stdout.write(`Test - Wallet3 wrap ${auto_amount} AUTO in anchor`);
process.stdout.write(`Test - Wallet3 wrap ${auto_amount} ABCT in anchor`);

let wallet3_client = await SigningCosmWasmClient.connectWithSigner(
localjuno.networkInfo.url,
Expand Down Expand Up @@ -286,7 +286,7 @@ export async function testAnchorInitialize(
// TEST: Anchor
//
// SCENARIO:
// 1. Wallet3 "unwrap"s some WTW to Cw20 token(AUTO) in anchor
// 1. Wallet3 "unwrap"s some WTW to Cw20 token(ABCT) in anchor
// ------------------------------------------------
export async function testAnchorUnwrapCw20(
junod: SigningCosmWasmClient,
Expand Down
2 changes: 1 addition & 1 deletion test-scripts/src/processes/tests/tokenWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function testTokenWrapperInitialize(
expect(result.native_token_denom == localjuno.contractsConsts.nativeTokenDenom).to.be.ok;
expect(result.fee_recipient == localjuno.addresses.wallet2).to.be.ok;
expect(result.fee_percentage == localjuno.contractsConsts.feePercentage.toString()).to.be.ok;
expect(result.is_native_allowed == (localjuno.contractsConsts.isNativeAllowed == 1).toString()).to.be.ok;
expect(result.is_native_allowed == localjuno.contractsConsts.isNativeAllowed.toString()).to.be.ok;
expect(result.wrapping_limit == localjuno.contractsConsts.tokenWrapperWrappingLimit).to.be.ok;
expect(result.proposal_nonce == "1").to.be.ok;

Expand Down
8 changes: 4 additions & 4 deletions test-scripts/src/processes/tests/vanchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function testVAnchorInitialize(
out_ext_amount: string,
out_fee: string,
): Promise<void> {
process.stdout.write(`Test - Wallet3 deposit ${in_auto_public_amount} AUTO to vanchor`);
process.stdout.write(`Test - Wallet3 deposit ${in_auto_public_amount} ABCT to vanchor`);

// Query the "amt_to_send" for "WrapAndDeposit" action
const amt_to_send_query: any = await junod.queryContractSmart(localjuno.contracts.tokenWrapper, {
Expand Down Expand Up @@ -287,7 +287,7 @@ export async function testVAnchorInitialize(
// TEST: VAnchor
//
// SCENARIO:
// 1. Wallet3 "wrap"s some CW20 token(AUTO) in anchor
// 1. Wallet3 "wrap"s some CW20 token(ABCT) in anchor
// ------------------------------------------------
export async function testVAnchorWrapCw20(
junod: SigningCosmWasmClient,
Expand All @@ -297,7 +297,7 @@ export async function testVAnchorInitialize(
wallet3: DirectSecp256k1HdWallet,
auto_amount: string,
): Promise<void> {
process.stdout.write(`Test - Wallet3 wrap ${auto_amount} AUTO in vanchor`);
process.stdout.write(`Test - Wallet3 wrap ${auto_amount} ABCT in vanchor`);

let wallet3_client = await SigningCosmWasmClient.connectWithSigner(
localjuno.networkInfo.url,
Expand Down Expand Up @@ -346,7 +346,7 @@ export async function testVAnchorInitialize(
// TEST: VAnchor
//
// SCENARIO:
// 1. Wallet3 "unwrap"s some WTW to Cw20 token(AUTO) in vanchor
// 1. Wallet3 "unwrap"s some WTW to Cw20 token(ABCT) in vanchor
// ------------------------------------------------
export async function testVAnchorUnwrapCw20(
junod: SigningCosmWasmClient,
Expand Down

0 comments on commit 5656499

Please sign in to comment.