Skip to content

Commit

Permalink
Create three deposits each for each node (spender)
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Apr 17, 2024
1 parent 4052226 commit 2f58ea0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
16 changes: 16 additions & 0 deletions gnt2-contracts/src/contracts/LockPayment/LockPayment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ interface ILockPayment {
function getDeposit(uint256 id) external view returns (DepositView memory);

function getDepositByNonce(uint64 nonce, address funder) external view returns (DepositView memory);

function getValidateDepositSignature() external pure returns (string memory);
}

/**
Expand Down Expand Up @@ -224,4 +226,18 @@ contract LockPayment is ILockPayment {
depositTransfer(id, payments);
closeDeposit(id);
}

function validateDeposit(uint256 id, address spender, uint128 amount, uint128 flatFeeAmount, int64 percentFee, uint64 validToTimestamp) public view returns (bool) {
Deposit memory deposit = deposits[id];
require(spender == deposit.spender, "msg.sender == deposit.spender");
require(amount == deposit.amount, "amount == deposit.amount");
require(flatFeeAmount == deposit.feeAmount, "flatFeeAmount == deposit.feeAmount");
require(percentFee == 0, "percentFee == 0 for this contract");
require(validToTimestamp < deposit.validTo, "validToTimestamp < deposit.validTo");
return true;
}

function getValidateDepositSignature() public pure returns (string memory) {
return "validateDeposit(uint256 id, address spender, uint128 amount, uint128 flatFeeAmount, int64 percentFee, uint64 validToTimestamp) public view returns (bool)";
}
}
18 changes: 12 additions & 6 deletions gnt2-docker-yagna/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,22 @@ async function start() {

console.log("Creating deposit for wallet 1...");
let GIGA = BigInt(1000000000);
let tx = await factories.NewGolemNetworkToken__factory.connect(newToken.address, provider.getSigner(wallets[0].address)).approve(lockContract.address, GIGA * GIGA * GIGA);
//funder actor of deposit, use wallet not used by yagna in goth tests
let funder = wallets[3].address;
let tx = await factories.NewGolemNetworkToken__factory.connect(newToken.address, provider.getSigner(funder)).approve(lockContract.address, GIGA * GIGA * GIGA);

console.log("Approved LockPayment to transfer NGNT: " + tx);
let lockPayment = factories.LockPayment__factory.connect(lockContract.address, provider.getSigner(wallets[0].address));
let validiTo = Math.floor(Date.now() / 1000) + 3600; //1 hour
let lockPayment = factories.LockPayment__factory.connect(lockContract.address, provider.getSigner(funder));
let validTo = Math.floor(Date.now() / 1000) + 3600; //1 hour

await lockPayment.createDeposit(1638, "0xd1d84f0e28d6fedf03c73151f98df95139700aa7", BigInt(100) * GIGA * GIGA, BigInt(10) * GIGA * GIGA, 0, validiTo);
await lockPayment.createDeposit(1638, "0x63fc2ad3d021a4d7e64323529a55a9442c444da0", BigInt(100) * GIGA * GIGA, BigInt(10) * GIGA * GIGA, 0, validTo);
let view = await lockPayment.getMyDeposit(1638);


console.log("Deposit created:\n contract address: " + lockPayment.address + "\n id: " + view.id._hex + "\n spender: " + view.spender + "\n funder: " + view.funder + "\n amount: " + view.amount + "\n fee: " + view.feeAmount + "\n expiration: " + view.validTo);
await lockPayment.createDeposit(1639, "0x17ec8597ff92c3f44523bdc65bf0f1be632917ff", BigInt(100) * GIGA * GIGA, BigInt(10) * GIGA * GIGA, 0, validTo);
view = await lockPayment.getMyDeposit(1639);
console.log("Deposit created:\n contract address: " + lockPayment.address + "\n id: " + view.id._hex + "\n spender: " + view.spender + "\n funder: " + view.funder + "\n amount: " + view.amount + "\n fee: " + view.feeAmount + "\n expiration: " + view.validTo);
await lockPayment.createDeposit(1640, "0xd1d84f0e28d6fedf03c73151f98df95139700aa7", BigInt(100) * GIGA * GIGA, BigInt(10) * GIGA * GIGA, 0, validTo);
view = await lockPayment.getMyDeposit(1640);
console.log("Deposit created:\n contract address: " + lockPayment.address + "\n id: " + view.id._hex + "\n spender: " + view.spender + "\n funder: " + view.funder + "\n amount: " + view.amount + "\n fee: " + view.feeAmount + "\n expiration: " + view.validTo);

console.log("Finished successfully!")
Expand Down

0 comments on commit 2f58ea0

Please sign in to comment.