mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Added getId, setId
This commit is contained in:
parent
79ed60b729
commit
1851104d6f
|
|
@ -13,7 +13,7 @@ import {Events} from "./events.sol";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
contract ERC20PermitResolver {
|
contract ERC20PermitResolver is Stores {
|
||||||
address private immutable daiAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F; // dai has a different implementation for permit
|
address private immutable daiAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F; // dai has a different implementation for permit
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -36,23 +36,35 @@ contract ERC20PermitResolver {
|
||||||
uint256 deadline,
|
uint256 deadline,
|
||||||
uint8 v,
|
uint8 v,
|
||||||
bytes32 r,
|
bytes32 r,
|
||||||
bytes32 s
|
bytes32 s,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
if(token == daiAddress){
|
if(token == daiAddress){
|
||||||
|
uint _amt = getUint(getId, amount);
|
||||||
|
|
||||||
DAITokenInterfaceWithPermit token = DAITokenInterfaceWithPermit(token);
|
DAITokenInterfaceWithPermit token = DAITokenInterfaceWithPermit(token);
|
||||||
|
|
||||||
token.permit(owner, address(this), nonce, deadline, true, v, r, s);
|
token.permit(owner, address(this), nonce, deadline, true, v, r, s);
|
||||||
token.transferFrom(owner, address(this), amount);
|
token.transferFrom(owner, address(this), _amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
uint _amt = getUint(getId, amount);
|
||||||
|
|
||||||
TokenInterfaceWithPermit token = TokenInterfaceWithPermit(token);
|
TokenInterfaceWithPermit token = TokenInterfaceWithPermit(token);
|
||||||
|
|
||||||
token.permit(owner, address(this), amount, deadline, v, r, s);
|
token.permit(owner, address(this), amount, deadline, v, r, s);
|
||||||
token.transferFrom(owner, address(this), amount);
|
token.transferFrom(owner, address(this), _amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
}
|
}
|
||||||
|
|
||||||
_eventName = "depositWithPermit(address,address,uint256,uint256,uint256,uint8,bytes32,bytes32)";
|
_eventName = "depositWithPermit(address,address,uint256,uint256,uint256,uint8,bytes32,bytes32,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
token,
|
token,
|
||||||
owner,
|
owner,
|
||||||
|
|
@ -61,7 +73,9 @@ contract ERC20PermitResolver {
|
||||||
deadline,
|
deadline,
|
||||||
v,
|
v,
|
||||||
r,
|
r,
|
||||||
s
|
s,
|
||||||
|
getId,
|
||||||
|
setId
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,20 +95,20 @@ describe("starting tests for aave", function () {
|
||||||
|
|
||||||
|
|
||||||
const hash1_for_encodePacked = soliditySha3('\x19\x01', DOMAIN_SEPARATOR, hash);
|
const hash1_for_encodePacked = soliditySha3('\x19\x01', DOMAIN_SEPARATOR, hash);
|
||||||
console.log("The hash that will be signed using private key: ", hash1_for_encodePacked);
|
//console.log("The hash that will be signed using private key: ", hash1_for_encodePacked);
|
||||||
|
|
||||||
|
|
||||||
//getting the r ,s ,v from the signature which will be passed as arguments in permit function
|
//getting the r ,s ,v from the signature which will be passed as arguments in permit function
|
||||||
const { v, r, s } = EthUtil.ecsign(Buffer.from(hash1_for_encodePacked.slice(2), 'hex'), Buffer.from(private_key.slice(2), 'hex'));
|
const { v, r, s } = EthUtil.ecsign(Buffer.from(hash1_for_encodePacked.slice(2), 'hex'), Buffer.from(private_key.slice(2), 'hex'));
|
||||||
|
|
||||||
//the sender calls permit function to take the allowance of fund transfer from the my_account(me) (Remember that they were interchanged)
|
//the sender calls permit function to take the allowance of fund transfer from the my_account(me) (Remember that they were interchanged)
|
||||||
await our_deployed_contract.connect(my_account).depositWithPermit(aave_token_address,my_account.address,0,value,deadline,v, hexlify(r), hexlify(s));
|
await our_deployed_contract.connect(my_account).depositWithPermit(aave_token_address,my_account.address,0,value,deadline,v, hexlify(r), hexlify(s), 0, 0);
|
||||||
|
|
||||||
|
|
||||||
//getting the finla balances
|
//getting the finla balances
|
||||||
expect(await aave_token_contract.balanceOf(my_account.address)).to.equal(0);
|
expect(await aave_token_contract.balanceOf(my_account.address)).to.equal(0);
|
||||||
expect(await aave_token_contract.balanceOf(our_deployed_contract.address)).to.equal(value);
|
expect(await aave_token_contract.balanceOf(our_deployed_contract.address)).to.equal(value);
|
||||||
console.log("The funds have been deposited to our contract through depositWithPermit function");
|
//console.log("The funds have been deposited to our contract through depositWithPermit function");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -92,20 +92,20 @@ describe("starting tests for dai", function () {
|
||||||
const hash = web3.utils.keccak256(encoded, {encoding: 'hex'});
|
const hash = web3.utils.keccak256(encoded, {encoding: 'hex'});
|
||||||
|
|
||||||
const hash1_for_encodePacked = soliditySha3('\x19\x01', DOMAIN_SEPARATOR, hash);
|
const hash1_for_encodePacked = soliditySha3('\x19\x01', DOMAIN_SEPARATOR, hash);
|
||||||
console.log("The hash that will be signed using private key: ", hash1_for_encodePacked);
|
//console.log("The hash that will be signed using private key: ", hash1_for_encodePacked);
|
||||||
|
|
||||||
|
|
||||||
//getting the r ,s ,v from the signature which will be passed as arguments in permit function
|
//getting the r ,s ,v from the signature which will be passed as arguments in permit function
|
||||||
const { v, r, s } = EthUtil.ecsign(Buffer.from(hash1_for_encodePacked.slice(2), 'hex'), Buffer.from(private_key.slice(2), 'hex'));
|
const { v, r, s } = EthUtil.ecsign(Buffer.from(hash1_for_encodePacked.slice(2), 'hex'), Buffer.from(private_key.slice(2), 'hex'));
|
||||||
|
|
||||||
//the sender calls permit function to take the allowance of fund transfer from the my_account(me) (Remember that they were interchanged)
|
//the sender calls permit function to take the allowance of fund transfer from the my_account(me) (Remember that they were interchanged)
|
||||||
await our_deployed_contract.depositWithPermit(dai_token_address,my_account.address,currentValidNonce,value,deadline,v, hexlify(r), hexlify(s));
|
await our_deployed_contract.depositWithPermit(dai_token_address,my_account.address,currentValidNonce,value,deadline,v, hexlify(r), hexlify(s),0 ,0);
|
||||||
|
|
||||||
|
|
||||||
//getting the finla balances
|
//getting the finla balances
|
||||||
expect(await aave_token_contract.balanceOf(my_account.address)).to.equal(0);
|
expect(await aave_token_contract.balanceOf(my_account.address)).to.equal(0);
|
||||||
expect(await aave_token_contract.balanceOf(our_deployed_contract.address)).to.equal(value);
|
expect(await aave_token_contract.balanceOf(our_deployed_contract.address)).to.equal(value);
|
||||||
console.log("The funds have been deposited to our contract through depositWithPermit function");
|
//console.log("The funds have been deposited to our contract through depositWithPermit function");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user