일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 머신러닝기초
- Vue.js
- 스마트컨트렉트 함수이름 중복 호출
- multicall
- 스마트컨트렉트 예약어 함수이름 중복
- erc4337 contract
- git rebase
- ambiguous function description
- rust 기초
- ethers type
- 계정추상화
- 컨트렉트 동일한 함수이름 호출
- vue기초
- ethers websocket
- 컨트렉트 배포 자동화
- Vue
- SBT표준
- ethers typescript
- 티스토리챌린지
- 스마트컨트렉트테스트
- 체인의정석
- 러스트기초
- ethers v6
- 오블완
- chainlink 설명
- 러스트 기초 학습
- erc4337
- 스마트 컨트렉트 함수이름 중복
- 러스트 기초
- ethers
- Today
- Total
체인의정석
스마트컨트렉트 테스트에 Infinite Approve 적용하기 본문
먼저 approve를 무한대로 해주는 infiniteApprove의 경우
Does the approve function on an ERC20 token need to be run once or before every relevant transaction?
I understand that an ERC20's approve() function has to be run before the token can be sent to another contract. But is this a one-time approval for msg.sender to be granted an approval status or do...
ethereum.stackexchange.com
해당 글에서 힌트를 얻을 수 있었다.
decimal = 18;
const infiniteVal: number = 2 ** 256 - 1;
const infiniteValBN: BigNumber = BigNumber.from(infiniteVal);
const bigIntTest: BigNumber = ethers.utils.parseUnits(
infiniteValBN.toString(),
decimal
);
그 결과 이런식으로 한번 테스트를 해봤는데 결과는
reason: 'overflow',
code: 'NUMERIC_FAULT',
fault: 'overflow',
operation: 'BigNumber.from',
value: 1.157920892373162e+77
이렇게 나왔다.
How to approve a token for spending on (Uniswap router contract)
Im trying to approve and later on swap my tokens on uniswap via web3py code. I am also using infura, not my own node. However, on both the swap and the approve I run into solidityErrors. The proble...
stackoverflow.com
보니까 web3 에선 위와 같이 되는것 같다.
https://github.com/ethers-io/ethers.js/discussions/2814
code: 'NUMERIC_FAULT', fault: 'overflow', operation: 'BigNumber.from' · Discussion #2814 · ethers-io/ethers.js
Hello! const tokenID = 96178001019380483532355422451609849948339356991030948866277126174730172245776; const someContract = new ethers.Contract(contractAddress, abi ,account) const result = await so...
github.com
보니까 bigNumber가 에러가 나는 것이므로 이때는 quote를 쓰라고 한다.
하지만 값 자체가 숫자형태로 안나오기 때문에 조금 더 찾아봤다.
https://forum.openzeppelin.com/t/using-the-maximum-integer-in-solidity/3000
Using the maximum integer in Solidity
There’s a variety of reasons you might want to know the maximum possible integer in solidity. One common use case is to approve a contract to transfer your tokens on your behalf: tokenContract.approve(exchangeContract, MAX_INT, { from: me }) Here I tell
forum.openzeppelin.com
오픈제플린 포럼에서 서치한 결과
const bigIntTest: BigNumber = ethers.utils.parseUnits(
"115792089237316195423570985008687907853269984665640564039457584007913129639935",
0
);
console.log("bigTest >>>", bigIntTest);
이렇게 하면 bignumber를 구할 수 있었다.
const bigIntTest: BigNumber = ethers.utils.parseUnits(
"115792089237316195423570985008687907853269984665640564039457584007913129639935",
0
);
it("test inifinite approve", async function () {
await erc20Token
.approve(ExampleContract.address, bigIntTest);
expect(
await erc20Token.allowance(userA.address, ExampleContract.address)
).equal(bigIntTest);
console.log("approve num", bigIntTest);
});
위와 같이 테스트 코드를 수정하니 infinite approve가 적용되었다.
어차피 고정값으로 넣으니 overflow가 나지 않게 처음부터 고정값으로 넣고 그 상태 그대로 bigNumber로 만들어서 입력값과 결과값체크에 사용하면 되는거엿다.
'블록체인 > Solidity' 카테고리의 다른 글
payable 사용시 발생하는 에러 ParserError: Expected primary expression. (0) | 2022.08.11 |
---|---|
Solidity) 스마트컨트렉트에서 이더리움을 보내는 방법 (0) | 2022.08.10 |
스마트컨트렉트에서 소수점 처리하는법과 엑셀에서 검산하는 방법 및 유의점 (0) | 2022.07.25 |
Solidity 0.8.0 버전에서 HashStruct안에 UUID 넣는 법 (0) | 2022.07.21 |
Solidity에서 자주 만나는 에러 "CompilerError: Stack too deep, try removing local variables." 그리고 에러에 대한 해결 방안 정리 , 이벤트 로그와 함수 입력값 구조체로 개수 줄이기 (0) | 2022.07.13 |