I want to check contract balance, when I tried locally it works fine but not on testnet, it always return 0
Code :
export class TokenHolder extends SmartContract {
init() {
super.init();
}
@method
async withdraw(
amount: UInt64
) {
const balance = this.account.balance.getAndRequireEquals();
Provable.log("balance", balance);
balance.assertGreaterThanOrEqual(amount, "Balance less than withdrawal amount");
this.balance.subInPlace(amount);
}
}
My vault :
export class Vault extends SmartContract {
// we need the token address to instantiate it
@state(PublicKey) tokenA = State<PublicKey>();
@state(UInt64) liquiditySupply = State<UInt64>();
async deploy(args: VaultDeployProps) {
await super.deploy(args);
args.tokenA.isEmpty().assertFalse("token empty");
this.account.permissions.set({
...Permissions.default(),
access: Permissions.none(),
setVerificationKey: Permissions.VerificationKey.proofOrSignature()
});
this.tokenA.set(args.tokenA);
}
@method async deposit(amount: UInt64) {
const addressA = this.tokenA.getAndRequireEquals();
amount.assertGreaterThan(UInt64.zero, "No amount A supplied");
let tokenContractA = new TokenA(addressA);
let dexX = AccountUpdate.create(this.address, tokenContractA.deriveTokenId());
let sender = this.sender.getUnconstrained();
await tokenContractA.transfer(sender, dexX, amount);
}
@method async withdraw(amount: UInt64) {
const addressA = this.tokenA.getAndRequireEquals();
const tokenContractA = new TokenA(addressA);
const holder = new TokenHolder(this.address, tokenContractA.deriveTokenId());
await holder.withdraw(amount);
const sender = this.sender.getUnconstrained();
await tokenContractA.transfer(holder.self, sender, amount);
}
}