Skip to content

Commit 5042cf0

Browse files
committed
removed approval requirement for cross chain transfers
1 parent b22c066 commit 5042cf0

File tree

3 files changed

+6
-72
lines changed

3 files changed

+6
-72
lines changed

contracts/satellite-chain/xc-ampleforth/XCAmple.sol

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ contract XCAmple is IERC20Upgradeable, OwnableUpgradeable {
374374

375375
/**
376376
* @dev Mint xcAmples to a beneficiary.
377+
* Only callable by the token controller.
377378
*
378379
* @param who The address of the beneficiary.
379380
* @param xcAmpleAmount The amount of xcAmple tokens to be minted.
@@ -390,25 +391,15 @@ contract XCAmple is IERC20Upgradeable, OwnableUpgradeable {
390391
}
391392

392393
/**
393-
* @dev Destroys `xcAmpleAmount` tokens from `who`, deducting from the caller's
394-
* allowance.
395-
*
396-
* This is only callable by the controller, because we only want to support burn for the
397-
* interchain-transfer case. Otherwise, AMPL on base chain could become locked in the vault.
398-
*
399-
* Requirements:
400-
*
401-
* - the caller must have allowance for ``who``'s tokens of at least
402-
* `xcAmpleAmount`.
394+
* @dev Destroys `xcAmpleAmount` tokens from `who`.
395+
* Only callable by the token controller.
403396
*
404397
* @param who The address of the beneficiary.
405398
* @param xcAmpleAmount The amount of xcAmple tokens to be burned.
406399
*/
407400
function burnFrom(address who, uint256 xcAmpleAmount) external onlyController {
408401
require(who != address(0), "XCAmple: burn address zero address");
409402

410-
_allowedXCAmples[who][msg.sender] = _allowedXCAmples[who][msg.sender].sub(xcAmpleAmount);
411-
412403
uint256 gonValue = xcAmpleAmount.mul(_gonsPerAMPL);
413404
_gonBalances[who] = _gonBalances[who].sub(gonValue);
414405
_totalSupply = _totalSupply.sub(xcAmpleAmount);

test/integration/chain_bridge.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ async function execXCSend (
259259
.connect(fromAccount)
260260
.approve(baseChainAmplContracts.tokenVault.address, amount);
261261
} else {
262-
await amplContractsMap[fromChain].xcAmple
263-
.connect(fromAccount)
264-
.approve(amplContractsMap[fromChain].xcAmpleController.address, amount);
262+
// NO Approval required!
265263
}
266264
}
267265

@@ -764,7 +762,7 @@ describe('Transfers scenarios', function () {
764762
});
765763

766764
describe('user does not approve Controller on satellite chain', function () {
767-
it('should revert', async function () {
765+
it('should NOT revert', async function () {
768766
// Setup by placing amples on satellite chain
769767
await checkBalancesAndSupply(
770768
['100000', '100000'],
@@ -804,7 +802,7 @@ describe('Transfers scenarios', function () {
804802
toAmplFixedPt('1'),
805803
false, // Use existing approval and don't auto-approve.
806804
),
807-
).to.be.reverted;
805+
).not.to.be.reverted;
808806
});
809807
});
810808
});

test/unit/satellite-chain/xc-ampleforth/xc_ample_burn.js

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ describe('XCAmple:burnFrom:accessControl', function () {
3636
await xcAmple
3737
.connect(deployer)
3838
.mint(otherUser.getAddress(), unitTokenAmount);
39-
await xcAmple
40-
.connect(otherUser)
41-
.approve(await deployer.getAddress(), unitTokenAmount);
4239
});
4340

4441
it('should NOT be callable by other user', async function () {
@@ -74,37 +71,19 @@ describe('XCAmple:burnFrom', () => {
7471
const mintAmt = toUFrgDenomination('1000000');
7572
await xcAmple.connect(deployer).mint(otherUser.getAddress(), mintAmt);
7673
const burnAmt = (await xcAmple.balanceOf(otherUser.getAddress())).add(1);
77-
await xcAmple
78-
.connect(otherUser)
79-
.approve(await deployer.getAddress(), burnAmt);
80-
8174
await expect(
8275
xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), burnAmt),
8376
).to.be.reverted;
8477
});
8578
});
8679

87-
describe('when burn value > approved amount', () => {
88-
it('should revert', async function () {
89-
const mintAmt = toUFrgDenomination('1000000');
90-
await xcAmple.connect(deployer).mint(otherUser.getAddress(), mintAmt);
91-
await xcAmple
92-
.connect(otherUser)
93-
.approve(await deployer.getAddress(), mintAmt.sub(1));
94-
await expect(
95-
xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), mintAmt),
96-
).to.be.reverted;
97-
});
98-
});
99-
10080
describe('when burn value = user balance', () => {
10181
const amt1 = toUFrgDenomination('1000000');
10282
const amt2 = toUFrgDenomination('12343588');
10383
const totalAmt = amt1.add(amt2);
10484
beforeEach(async function () {
10585
await xcAmple.connect(deployer).mint(deployer.getAddress(), amt2);
10686
await xcAmple.connect(deployer).mint(otherUser.getAddress(), amt1);
107-
await xcAmple.connect(otherUser).approve(deployer.getAddress(), amt1);
10887
});
10988
it('should burn tokens from wallet', async function () {
11089
await xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), amt1);
@@ -120,16 +99,6 @@ describe('XCAmple:burnFrom', () => {
12099
await xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), amt1);
121100
expect(await xcAmple.totalSupply()).to.eq(amt2);
122101
});
123-
it('should reduce the approved amount', async function () {
124-
const allowanceBefore = await xcAmple.allowance(
125-
otherUser.getAddress(),
126-
deployer.getAddress(),
127-
);
128-
await xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), amt1);
129-
expect(
130-
await xcAmple.allowance(otherUser.getAddress(), deployer.getAddress()),
131-
).to.eq(allowanceBefore - amt1);
132-
});
133102
it('should log Transfer to zero address', async function () {
134103
await expect(
135104
xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), amt1),
@@ -150,7 +119,6 @@ describe('XCAmple:burnFrom', () => {
150119

151120
beforeEach(async function () {
152121
await xcAmple.connect(deployer).mint(otherUser.getAddress(), mintAmt);
153-
await xcAmple.connect(otherUser).approve(deployer.getAddress(), mintAmt);
154122
});
155123
it('should burn tokens from wallet', async function () {
156124
await xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), burnAmt);
@@ -163,16 +131,6 @@ describe('XCAmple:burnFrom', () => {
163131
await xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), burnAmt);
164132
expect(await xcAmple.totalSupply()).to.eq(remainingBal);
165133
});
166-
it('should reduce the approved amount', async function () {
167-
const allowanceBefore = await xcAmple.allowance(
168-
otherUser.getAddress(),
169-
deployer.getAddress(),
170-
);
171-
await xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), burnAmt);
172-
expect(
173-
await xcAmple.allowance(otherUser.getAddress(), deployer.getAddress()),
174-
).to.eq(allowanceBefore - burnAmt);
175-
});
176134
it('should log Transfer to zero address', async function () {
177135
await expect(
178136
xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), burnAmt),
@@ -193,9 +151,6 @@ describe('XCAmple:burnFrom', () => {
193151
beforeEach(async function () {
194152
await xcAmple.rebase(1, MAX_SUPPLY);
195153
await xcAmple.connect(deployer).mint(otherUser.getAddress(), MAX_SUPPLY);
196-
await xcAmple
197-
.connect(otherUser)
198-
.approve(deployer.getAddress(), MAX_SUPPLY);
199154
});
200155

201156
it('should burn tokens from wallet', async function () {
@@ -209,16 +164,6 @@ describe('XCAmple:burnFrom', () => {
209164
await xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), burnAmt);
210165
expect(await xcAmple.totalSupply()).to.eq(remainingBal);
211166
});
212-
it('should reduce the approved amount', async function () {
213-
const allowanceBefore = await xcAmple.allowance(
214-
otherUser.getAddress(),
215-
deployer.getAddress(),
216-
);
217-
await xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), burnAmt);
218-
expect(
219-
await xcAmple.allowance(otherUser.getAddress(), deployer.getAddress()),
220-
).to.eq(allowanceBefore.sub(burnAmt));
221-
});
222167
it('should log Transfer to zero address', async function () {
223168
await expect(
224169
xcAmple.connect(deployer).burnFrom(otherUser.getAddress(), burnAmt),

0 commit comments

Comments
 (0)