Skip to content

Commit

Permalink
Merge pull request #146 from BeanstalkFarms/ebip6
Browse files Browse the repository at this point in the history
EBIP-6: Resolve EBIP-4 and EBIP-5
  • Loading branch information
publiuss committed Nov 16, 2022
2 parents ffd0724 + 81a7c12 commit 4ee40ac
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 120 deletions.
19 changes: 7 additions & 12 deletions protocol/abi/Beanstalk.json
Expand Up @@ -4915,6 +4915,11 @@
"name": "token",
"type": "address"
},
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "address",
"name": "recipient",
Expand All @@ -4925,18 +4930,13 @@
"name": "amount",
"type": "uint256"
},
{
"internalType": "enum LibTransfer.From",
"name": "fromMode",
"type": "uint8"
},
{
"internalType": "enum LibTransfer.To",
"name": "toMode",
"type": "uint8"
}
],
"name": "transferToken",
"name": "transferInternalTokenFrom",
"outputs": [],
"stateMutability": "payable",
"type": "function"
Expand All @@ -4948,11 +4948,6 @@
"name": "token",
"type": "address"
},
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "address",
"name": "recipient",
Expand All @@ -4974,7 +4969,7 @@
"type": "uint8"
}
],
"name": "transferTokenFrom",
"name": "transferToken",
"outputs": [],
"stateMutability": "payable",
"type": "function"
Expand Down
13 changes: 3 additions & 10 deletions protocol/contracts/farm/facets/TokenFacet.sol
Expand Up @@ -61,31 +61,24 @@ contract TokenFacet is ReentrancyGuard {
);
}

function transferTokenFrom(
function transferInternalTokenFrom(
IERC20 token,
address sender,
address recipient,
uint256 amount,
LibTransfer.From fromMode,
LibTransfer.To toMode
) external payable nonReentrant {
uint256 beforeAmount = LibBalance.getInternalBalance(sender, token);
LibTransfer.transferToken(
token,
sender,
recipient,
amount,
fromMode,
LibTransfer.From.INTERNAL,
toMode
);

if (sender != msg.sender) {
uint256 deltaAmount = beforeAmount.sub(
LibBalance.getInternalBalance(sender, token)
);
if (deltaAmount > 0) {
LibTokenApprove.spendAllowance(sender, msg.sender, token, deltaAmount);
}
LibTokenApprove.spendAllowance(sender, msg.sender, token, amount);
}
}

Expand Down
23 changes: 23 additions & 0 deletions protocol/contracts/farm/init/InitEBip6.sol
@@ -0,0 +1,23 @@
/*
SPDX-License-Identifier: MIT
*/

pragma solidity =0.7.6;
pragma experimental ABIEncoderV2;

import {AppStorage} from "../AppStorage.sol";

/**
* @author Publius
* @title InitEBip6 updates the mappings of Pod Orders created before BIP-29.
**/
contract InitEBip6 {
AppStorage internal s;

function init() external {
s.podOrders[0x6f668ae24be6e177f8584600dbffea6e07f260e08e21fa47792385913e786da3] = 10_491_929_346;
s.podOrders[0xf47df2678d29e9d57c5e9ed5f8c990e71910918154a2ed6d5235718035d7d8b0] = 1_466_423;
s.podOrders[0x186c6468ca4d3ce2575b9527fcf42cc3c86ab7cc915a550c9e84c5443691607a] = 380;
}

}
44 changes: 44 additions & 0 deletions protocol/scripts/ebips.js
@@ -0,0 +1,44 @@
const fs = require('fs')
const { getBeanstalk, impersonateBeanstalkOwner, mintEth } = require("../utils")

async function ebip6(mock = true, account = undefined) {
if (account == undefined) {
account = await impersonateBeanstalkOwner()
await mintEth(account.address)
}

beanstalk = await getBeanstalk()
const tokenFacet = await (await ethers.getContractFactory("TokenFacet", account)).deploy()
console.log(`Token Facet deployed to: ${tokenFacet.address}`)
const ebip6 = await (await ethers.getContractFactory("InitEBip6", account)).deploy()
console.log(`EBIP-6 deployed to: ${ebip6.address}`)
const dc = {
diamondCut: [
[
'0x0c9F436FBEf08914c1C68fe04bD573de6e327776',
'0',
['0xdf18a3ee', '0x845a022b', '0x82c65124']
],
[
tokenFacet.address,
'0',
['0xd3f4ec6f']
]
],
initFacetAddress: ebip6.address,
functionCall: ebip6.interface.encodeFunctionData('init', [])
}
if (mock) {
const receipt = await beanstalk.connect(account).diamondCut(...Object.values(dc))
} else {
const encodedDiamondCut = await beanstalk.interface.encodeFunctionData('diamondCut', Object.values(dc))
console.log(JSON.stringify(dc, null, 4))
console.log("Encoded: -------------------------------------------------------------")
console.log(encodedDiamondCut)
const dcName = `diamondCut-${'InitEBip6'}-${Math.floor(Date.now() / 1000)}-facets.json`
await fs.writeFileSync(`./diamondCuts/${dcName}`, JSON.stringify({diamondCut: dc, encoded: encodedDiamondCut }, null, 4));
return dc
}
}

exports.ebip6 = ebip6

0 comments on commit 4ee40ac

Please sign in to comment.