flowchart LR
Alice
subgraph run["Agoric (RUN)"]
borrow(["Borrow against staked BLD"])
borrowvault(["Borrow against ATOM in a vault"])
trade(["Trade USDC for RUN"])
end
Alice --> borrow
Alice --> borrowvault
Alice --> trade
agoric-sdk/packages/run-protocol/test/getRUN-test-steps.js
['buyBLD', 80000n],
['stakeBLD', 80000n],
['lienBLD', 8000n],
['borrowRUN', 1000n],
['setCollateralizationRatio', [750n, 100n]],
['borrowMoreRUN', 500n, false],
['checkRUNBalance', 1000n],
['checkBLDLiened', 8000n],
['checkBLDLiened', 8000n],
['checkRUNBalance', 1000n],
['payoffRUN', 1000n],
['checkRUNDebt', 0n],
['checkBLDLiened', 0n],
['checkRUNBalance', 0n],
sequenceDiagram
autonumber
actor founder as Founder
actor alice as Alice
participant validator as Validator
participant rs as RUNStake Contract
participant econ as Economic Committee
rs ->> rs: initial Ratio = 5:1, Price = 1.25
founder ->> alice: transfer 80000 BLD
alice ->> validator: delegate 80000 BLD
alice ->> alice: lien 8000 BLD
alice ->> rs: Give = Attestation =8000 BLD, Want = 1000 RUN
Note Right of rs: Atomic & Offer Safe
rs ->> alice: SUCCESS Borrow 1000 RUN
econ ->> rs: Ratio = 7.5:1
alice ->> rs: Give = Attestation =8000 BLD, Want = 500 RUN
rs ->> alice: FAIL Borrow 500 RUN
alice ->> rs: Give = 1000 RUN, Want = Attestation =8000 BLD
rs ->> alice: SUCCESS Attestation = 8000 BLD
agoric-sdk/packages/run-protocol/test/test-getRUN.js
borrowRUN: async n => {
const attAmt = await E(attPurse).getCurrentAmount();
const attPmt = await E(attPurse).withdraw(attAmt);
const proposal = harden({
give: { Attestation: attAmt },
want: { RUN: AmountMath.make(runBrand, n * micro.unit) },
});
const seat = E(zoe).offer(
E(getRUN.publicFacet).makeLoanInvitation(),
proposal,
harden({ Attestation: attPmt }),
);
const runPmt = await E(seat).getPayout('RUN');
E(runPurse).deposit(runPmt);
offerResult = await E(seat).getOfferResult();
},
sequenceDiagram
participant driver
participant attPurse
participant runPurse
participant pf as getRUN.publicFacet
participant zoe as Zoe
participant oh as getRUN.offerHandler
participant seat as Seat
driver ->> attPurse: getCurrentAmount
attPurse ->> driver: attAmt
driver ->> attPurse: withdraw(attAmt)
attPurse ->> driver: attAmt
driver ->>pf: makeLoanInvitation
pf ->> driver: LoanInvitation
driver ->> zoe: offer(LoanInvitation, proposal {Give: attAmt, Want: n}, attPmt
zoe ->> oh: proposal {Give: attAmt, Want: n}
zoe ->> driver: seat
zoe ->> seat: getPayout('RUN')
seat ->> zoe: runPmt
driver ->> runPurse: deposit(runPmt)
driver ->> seat: getOfferResult
seat ->> driver: offerResult