Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for 3184 -- decrement first #3224

Merged
merged 2 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/treasury/src/collectRewardFees.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export const makeMakeCollectFeesInvitation = (
const { zcfSeat: transferSeat } = zcf.makeEmptySeatKit();
await E.get(offerTo(zcf, invitation, {}, {}, transferSeat)).deposited;

feeSeat.decrementBy(
seat.incrementBy({ RUN: feeSeat.getAmountAllocated('RUN', runBrand) }),
seat.incrementBy(
feeSeat.decrementBy({ RUN: feeSeat.getAmountAllocated('RUN', runBrand) }),
);
transferSeat.decrementBy(
seat.incrementBy({
seat.incrementBy(
transferSeat.decrementBy({
RUN: transferSeat.getAmountAllocated('RUN', runBrand),
}),
);
Expand Down
6 changes: 3 additions & 3 deletions packages/treasury/src/stablecoinMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export async function start(zcf) {
* @type {TransferReward}
*/
function transferReward(amount, fromSeat) {
fromSeat.decrementBy(
rewardPoolSeat.incrementBy({
rewardPoolSeat.incrementBy(
fromSeat.decrementBy({
RUN: amount,
}),
);
Expand Down Expand Up @@ -159,7 +159,7 @@ export async function start(zcf) {

// trade the governance tokens for collateral, putting the
// collateral on Secondary to be positioned for Autoswap
govSeat.decrementBy(seat.incrementBy({ Governance: govAmount }));
seat.incrementBy(govSeat.decrementBy({ Governance: govAmount }));
govSeat.incrementBy({ Secondary: collateralIn });
seat.decrementBy({ Collateral: collateralIn });

Expand Down
22 changes: 11 additions & 11 deletions packages/treasury/src/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ export function makeVaultKit(
assert(AmountMath.isGTE(runReturned, runDebt));

// Return any overpayment
seat.decrementBy(vaultSeat.incrementBy({ RUN: runDebt }));
vaultSeat.decrementBy(
seat.incrementBy({ Collateral: getCollateralAllocated(vaultSeat) }),
vaultSeat.incrementBy(seat.decrementBy({ RUN: runDebt }));
seat.incrementBy(
vaultSeat.decrementBy({ Collateral: getCollateralAllocated(vaultSeat) }),
);
zcf.reallocate(seat, vaultSeat);

Expand Down Expand Up @@ -236,12 +236,12 @@ export function makeVaultKit(
function stageCollateral(seat) {
const proposal = seat.getProposal();
if (proposal.want.Collateral) {
vaultSeat.decrementBy(
seat.incrementBy({ Collateral: proposal.want.Collateral }),
seat.incrementBy(
vaultSeat.decrementBy({ Collateral: proposal.want.Collateral }),
);
} else if (proposal.give.Collateral) {
seat.decrementBy(
vaultSeat.incrementBy({ Collateral: proposal.give.Collateral }),
vaultSeat.incrementBy(
seat.decrementBy({ Collateral: proposal.give.Collateral }),
);
}
}
Expand Down Expand Up @@ -282,14 +282,14 @@ export function makeVaultKit(
function stageRun(seat) {
const proposal = seat.getProposal();
if (proposal.want.RUN) {
vaultSeat.decrementBy(seat.incrementBy({ RUN: proposal.want.RUN }));
seat.incrementBy(vaultSeat.decrementBy({ RUN: proposal.want.RUN }));
} else if (proposal.give.RUN) {
// We don't allow runDebt to be negative, so we'll refund overpayments
const acceptedRun = AmountMath.isGTE(proposal.give.RUN, runDebt)
? runDebt
: proposal.give.RUN;

seat.decrementBy(vaultSeat.incrementBy({ RUN: acceptedRun }));
vaultSeat.incrementBy(seat.decrementBy({ RUN: acceptedRun }));
}
}

Expand Down Expand Up @@ -411,8 +411,8 @@ export function makeVaultKit(

runMint.mintGains({ RUN: runDebt }, vaultSeat);

vaultSeat.decrementBy(seat.incrementBy({ RUN: wantedRun }));
seat.decrementBy(vaultSeat.incrementBy({ Collateral: collateralAmount }));
seat.incrementBy(vaultSeat.decrementBy({ RUN: wantedRun }));
vaultSeat.incrementBy(seat.decrementBy({ Collateral: collateralAmount }));
zcf.reallocate(vaultSeat, seat);
manager.transferReward(fee, vaultSeat);

Expand Down
4 changes: 2 additions & 2 deletions packages/treasury/test/vault-contract-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export async function start(zcf) {
};

function transferReward(amount, fromSeat) {
fromSeat.decrementBy(
stableCoinSeat.incrementBy({
stableCoinSeat.incrementBy(
fromSeat.decrementBy({
RUN: amount,
}),
);
Expand Down
10 changes: 5 additions & 5 deletions packages/zoe/src/contracts/autoswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ const start = async zcf => {
Central: AmountMath.make(centralIn, brands.Central),
Secondary: secondaryAmount,
};
seat.decrementBy(poolSeat.incrementBy(liquidityDeposited));
poolSeat.decrementBy(seat.incrementBy({ Liquidity: liquidityAmountOut }));
poolSeat.incrementBy(seat.decrementBy(liquidityDeposited));
seat.incrementBy(poolSeat.decrementBy({ Liquidity: liquidityAmountOut }));

zcf.reallocate(poolSeat, seat);

Expand Down Expand Up @@ -294,11 +294,11 @@ const start = async zcf => {
Secondary: newUserSecondaryAmount,
};

removeLiqSeat.decrementBy(
poolSeat.incrementBy({ Liquidity: userAllocation.Liquidity }),
poolSeat.incrementBy(
removeLiqSeat.decrementBy({ Liquidity: userAllocation.Liquidity }),
);

poolSeat.decrementBy(removeLiqSeat.incrementBy(liquidityRemoved));
removeLiqSeat.incrementBy(poolSeat.decrementBy(liquidityRemoved));

zcf.reallocate(poolSeat, removeLiqSeat);

Expand Down
8 changes: 4 additions & 4 deletions packages/zoe/src/contracts/callSpread/fundedCallSpread.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ const start = async zcf => {
give: { Collateral: null },
want: { LongOption: null, ShortOption: null },
});
creatorSeat.decrementBy(
collateralSeat.incrementBy({ Collateral: settlementAmount }),
collateralSeat.incrementBy(
creatorSeat.decrementBy({ Collateral: settlementAmount }),
);
collateralSeat.decrementBy(
creatorSeat.incrementBy({
creatorSeat.incrementBy(
collateralSeat.decrementBy({
LongOption: longAmount,
ShortOption: shortAmount,
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/src/contracts/callSpread/payoffHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function makePayoffHandler(zcf, seatPromiseKits, collateralSeat) {
seatPromise.then(seat => {
const totalCollateral = terms.settlementAmount;
const seatPortion = multiplyBy(totalCollateral, sharePercent);
collateralSeat.decrementBy(seat.incrementBy({ Collateral: seatPortion }));
seat.incrementBy(collateralSeat.decrementBy({ Collateral: seatPortion }));
zcf.reallocate(seat, collateralSeat);
seat.exit();
seatsExited += 1;
Expand Down
6 changes: 3 additions & 3 deletions packages/zoe/src/contracts/callSpread/pricedCallSpread.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ const start = zcf => {
X`wanted option not a match`,
);

collateralSeat.decrementBy(depositSeat.incrementBy(spreadAmount));
depositSeat.decrementBy(
collateralSeat.incrementBy({ Collateral: newCollateral }),
depositSeat.incrementBy(collateralSeat.decrementBy(spreadAmount));
collateralSeat.incrementBy(
depositSeat.decrementBy({ Collateral: newCollateral }),
);

zcf.reallocate(collateralSeat, depositSeat);
Expand Down
4 changes: 2 additions & 2 deletions packages/zoe/src/contracts/loan/addCollateral.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const makeAddCollateralInvitation = (zcf, config) => {
want: {},
});

addCollateralSeat.decrementBy(
collateralSeat.incrementBy({
collateralSeat.incrementBy(
addCollateralSeat.decrementBy({
Collateral: addCollateralSeat.getAmountAllocated('Collateral'),
}),
);
Expand Down
6 changes: 3 additions & 3 deletions packages/zoe/src/contracts/loan/borrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ export const makeBorrowInvitation = (zcf, config) => {
const { zcfSeat: collateralSeat } = zcf.makeEmptySeatKit();

// Transfer the wanted Loan amount to the borrower
lenderSeat.decrementBy(borrowerSeat.incrementBy({ Loan: loanWanted }));
borrowerSeat.incrementBy(lenderSeat.decrementBy({ Loan: loanWanted }));

// Transfer *all* collateral to the collateral seat.
borrowerSeat.decrementBy(
collateralSeat.incrementBy({ Collateral: collateralGiven }),
collateralSeat.incrementBy(
borrowerSeat.decrementBy({ Collateral: collateralGiven }),
);
zcf.reallocate(lenderSeat, borrowerSeat, collateralSeat);

Expand Down
4 changes: 2 additions & 2 deletions packages/zoe/src/contracts/loan/close.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const makeCloseLoanInvitation = (zcf, config) => {
// required Loan amount. Any excess Loan amount is kept by the repaySeat.
// Transfer the repaid loan amount to the lender

collateralSeat.decrementBy(
repaySeat.incrementBy({
repaySeat.incrementBy(
collateralSeat.decrementBy({
Collateral: collateralSeat.getAmountAllocated(
'Collateral',
collateralBrand,
Expand Down
4 changes: 2 additions & 2 deletions packages/zoe/src/contracts/loan/scheduleLiquidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export const scheduleLiquidation = (zcf, configWithBorrower) => {
// collateral is on the collateral seat. If an error occurs, we
// reallocate the collateral to the lender and shutdown the
// contract, kicking out any remaining seats.
collateralSeat.decrementBy(
lenderSeat.incrementBy({ Collateral: allCollateral }),
lenderSeat.incrementBy(
collateralSeat.decrementBy({ Collateral: allCollateral }),
);
zcf.reallocate(lenderSeat, collateralSeat);
zcf.shutdownWithFailure(err);
Expand Down
14 changes: 7 additions & 7 deletions packages/zoe/src/contracts/multipoolAutoswap/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ export const makeAddPool = (
liquidityZcfMint.mintGains({ Liquidity: liquidityAmountOut }, poolSeat);
liqTokenSupply += liquidityValueOut;

zcfSeat.decrementBy(
poolSeat.incrementBy({
poolSeat.incrementBy(
zcfSeat.decrementBy({
Central: zcfSeat.getCurrentAllocation().Central,
Secondary: secondaryAmount,
}),
);

poolSeat.decrementBy(
zcfSeat.incrementBy({ Liquidity: liquidityAmountOut }),
zcfSeat.incrementBy(
poolSeat.decrementBy({ Liquidity: liquidityAmountOut }),
);
zcf.reallocate(poolSeat, zcfSeat);
zcfSeat.exit();
Expand Down Expand Up @@ -248,9 +248,9 @@ export const makeAddPool = (

liqTokenSupply -= liquidityValueIn;

userSeat.decrementBy(poolSeat.incrementBy({ Liquidity: liquidityIn }));
poolSeat.decrementBy(
userSeat.incrementBy({
poolSeat.incrementBy(userSeat.decrementBy({ Liquidity: liquidityIn }));
userSeat.incrementBy(
poolSeat.decrementBy({
Central: centralTokenAmountOut,
Secondary: tokenKeywordAmountOut,
}),
Expand Down
6 changes: 3 additions & 3 deletions packages/zoe/src/contracts/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const start = async zcf => {
? feeSeat.getCurrentAllocation()
: seat.getProposal().want;

feeSeat.decrementBy(seat.incrementBy(gains));
seat.incrementBy(feeSeat.decrementBy(gains));
zcf.reallocate(seat, feeSeat);
seat.exit();
return 'Successfully withdrawn';
Expand All @@ -46,7 +46,7 @@ const start = async zcf => {
makeShutdownInvitation: () => {
const shutdown = seat => {
revoked = true;
feeSeat.decrementBy(seat.incrementBy(feeSeat.getCurrentAllocation()));
seat.incrementBy(feeSeat.decrementBy(feeSeat.getCurrentAllocation()));
zcf.reallocate(seat, feeSeat);
zcf.shutdown(revokedMsg);
};
Expand Down Expand Up @@ -84,7 +84,7 @@ const start = async zcf => {
const fee = querySeat.getAmountAllocated('Fee', feeBrand);
const { requiredFee, reply } = await E(handler).onQuery(query, fee);
if (requiredFee) {
querySeat.decrementBy(feeSeat.incrementBy({ Fee: requiredFee }));
feeSeat.incrementBy(querySeat.decrementBy({ Fee: requiredFee }));
zcf.reallocate(feeSeat, querySeat);
}
querySeat.exit();
Expand Down
4 changes: 2 additions & 2 deletions packages/zoe/src/contracts/otcDesk.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const start = zcf => {
const addInventory = seat => {
assertProposalShape(seat, { want: {} });
// Take everything in this seat and add it to the marketMakerSeat
seat.decrementBy(marketMakerSeat.incrementBy(seat.getCurrentAllocation()));
marketMakerSeat.incrementBy(seat.decrementBy(seat.getCurrentAllocation()));
zcf.reallocate(marketMakerSeat, seat);
seat.exit();
return 'Inventory added';
Expand All @@ -108,7 +108,7 @@ const start = zcf => {
const removeInventory = seat => {
assertProposalShape(seat, { give: {} });
const { want } = seat.getProposal();
marketMakerSeat.decrementBy(seat.incrementBy(want));
seat.incrementBy(marketMakerSeat.decrementBy(want));
zcf.reallocate(marketMakerSeat, seat);
seat.exit();
return 'Inventory removed';
Expand Down
4 changes: 2 additions & 2 deletions packages/zoe/src/contracts/sellItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ const start = zcf => {
);

// Reallocate.
buyerSeat.decrementBy(sellerSeat.incrementBy({ Money: providedMoney }));
sellerSeat.decrementBy(buyerSeat.incrementBy({ Items: wantedItems }));
sellerSeat.incrementBy(buyerSeat.decrementBy({ Money: providedMoney }));
buyerSeat.incrementBy(sellerSeat.decrementBy({ Items: wantedItems }));
zcf.reallocate(buyerSeat, sellerSeat);

// The buyer's offer has been processed.
Expand Down
8 changes: 5 additions & 3 deletions packages/zoe/test/unitTests/bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ const start = async zcf => {
assertProposalShape(funderSeat, endowBounty);

function payOffBounty(seat) {
funderSeat.decrementBy(
seat.incrementBy({ Bounty: funderSeat.getCurrentAllocation().Bounty }),
seat.incrementBy(
funderSeat.decrementBy({
Bounty: funderSeat.getCurrentAllocation().Bounty,
}),
);

zcf.reallocate(funderSeat, seat);
Expand Down Expand Up @@ -57,7 +59,7 @@ const start = async zcf => {
);

// The funder gets the fee regardless of the outcome.
bountySeat.decrementBy(funderSeat.incrementBy({ Fee: feeAmount }));
funderSeat.incrementBy(bountySeat.decrementBy({ Fee: feeAmount }));
zcf.reallocate(funderSeat, bountySeat);

const wakeHandler = Far('wakeHandler', {
Expand Down