-
Notifications
You must be signed in to change notification settings - Fork 214
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
Add a coreEval for vaults auctions and test in a3p #9911
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
03a944e
chore: move a:upgrade-next so vaults-auctions can be first
Chris-Hibbert 9da0239
chore: npx yarn-deduuplicate
Chris-Hibbert b010d2e
test: a3p-integration test for vaults and auctions coreEval
Chris-Hibbert f6c7074
chore: fixup noble/hashes patch
Chris-Hibbert f42adc3
feat: link the auctions and vaults updates so they run sequenctially
Chris-Hibbert d064567
feat: remove vaults, auctions, and priceFeeds from upgrade.go
Chris-Hibbert d1a4c51
chore: move BID_OFFER_ID out of agd-tools
Chris-Hibbert aa11426
refactor: rename auctionsDone flag, remove it after use
Chris-Hibbert 5a1c729
docs: clarify comments in test.sh
Chris-Hibbert 9ce0c22
chore: update walletFactory incarnation for e:upgrade-next
Chris-Hibbert de3b258
chore: provisionPool test in e:upgrade-next uses OLIVES and LEMONS
Chris-Hibbert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# CoreEvalProposal to upgrade vaults and auctions | ||
|
||
The `submission` for this proposal is automatically generated during `yarn build` | ||
in [a3p-integration](../..) using the code in agoric-sdk through | ||
[build-all-submissions.sh](../../scripts/build-all-submissions.sh) and | ||
[build-submission.sh](../../scripts/build-submission.sh). |
203 changes: 203 additions & 0 deletions
203
a3p-integration/proposals/a:vaults-auctions/agd-tools.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
import { | ||
agd, | ||
agops, | ||
agopsLocation, | ||
CHAINID, | ||
executeCommand, | ||
executeOffer, | ||
GOV1ADDR, | ||
GOV2ADDR, | ||
GOV3ADDR, | ||
VALIDATORADDR, | ||
waitForBlock, | ||
} from '@agoric/synthetic-chain'; | ||
|
||
const ORACLE_ADDRESSES = [GOV1ADDR, GOV2ADDR, GOV3ADDR]; | ||
|
||
const queryVstorage = path => | ||
agd.query('vstorage', 'data', '--output', 'json', path); | ||
|
||
// XXX use endo/marshal? | ||
const getQuoteBody = async path => { | ||
const queryOut = await queryVstorage(path); | ||
|
||
const body = JSON.parse(JSON.parse(queryOut.value).values[0]); | ||
return JSON.parse(body.body.substring(1)); | ||
}; | ||
|
||
export const getOracleInstance = async price => { | ||
const instanceRec = await queryVstorage(`published.agoricNames.instance`); | ||
|
||
const value = JSON.parse(instanceRec.value); | ||
const body = JSON.parse(value.values.at(-1)); | ||
|
||
const feeds = JSON.parse(body.body.substring(1)); | ||
const feedName = `${price}-USD price feed`; | ||
|
||
const key = Object.keys(feeds).find(k => feeds[k][0] === feedName); | ||
if (key) { | ||
return body.slots[key]; | ||
} | ||
return null; | ||
}; | ||
|
||
export const checkForOracle = async (t, name) => { | ||
const instance = await getOracleInstance(name); | ||
t.truthy(instance); | ||
}; | ||
|
||
export const registerOraclesForBrand = async (brandIn, oraclesByBrand) => { | ||
await null; | ||
const promiseArray = []; | ||
|
||
const oraclesWithID = oraclesByBrand.get(brandIn); | ||
for (const oracle of oraclesWithID) { | ||
const { address, offerId } = oracle; | ||
promiseArray.push( | ||
executeOffer( | ||
address, | ||
agops.oracle('accept', '--offerId', offerId, `--pair ${brandIn}.USD`), | ||
), | ||
); | ||
} | ||
|
||
return Promise.all(promiseArray); | ||
}; | ||
|
||
/** | ||
* Generate a consistent map of oracleIDs for a brand that can be used to | ||
* register oracles or to push prices. The baseID changes each time new | ||
* invitations are sent/accepted, and need to be maintained as constants in | ||
* scripts that use the oracles. Each oracleAddress and brand needs a unique | ||
* offerId, so we create recoverable IDs using the brandName and oracle id, | ||
* mixed with the upgrade at which the invitations were accepted. | ||
* | ||
* @param {string} baseId | ||
* @param {string} brandName | ||
*/ | ||
const addOraclesForBrand = (baseId, brandName) => { | ||
const oraclesWithID = []; | ||
for (let i = 0; i < ORACLE_ADDRESSES.length; i += 1) { | ||
const oracleAddress = ORACLE_ADDRESSES[i]; | ||
const offerId = `${brandName}.${baseId}.${i}`; | ||
oraclesWithID.push({ address: oracleAddress, offerId }); | ||
} | ||
return oraclesWithID; | ||
}; | ||
|
||
export const addPreexistingOracles = async (brandIn, oraclesByBrand) => { | ||
await null; | ||
|
||
const oraclesWithID = []; | ||
for (let i = 0; i < ORACLE_ADDRESSES.length; i += 1) { | ||
const oracleAddress = ORACLE_ADDRESSES[i]; | ||
|
||
const path = `published.wallet.${oracleAddress}.current`; | ||
const wallet = await getQuoteBody(path); | ||
const idToInvitation = wallet.offerToUsedInvitation.find(([k]) => { | ||
return !isNaN(k[0]); | ||
}); | ||
if (idToInvitation) { | ||
oraclesWithID.push({ | ||
address: oracleAddress, | ||
offerId: idToInvitation[0], | ||
}); | ||
} | ||
} | ||
|
||
oraclesByBrand.set(brandIn, oraclesWithID); | ||
}; | ||
|
||
/** | ||
* Generate a consistent map of oracleIDs and brands that can be used to | ||
* register oracles or to push prices. The baseID changes each time new | ||
* invitations are sent/accepted, and need to be maintained as constants in | ||
* scripts that use these records to push prices. | ||
* | ||
* @param {string} baseId | ||
* @param {string[]} brandNames | ||
*/ | ||
export const generateOracleMap = (baseId, brandNames) => { | ||
const oraclesByBrand = new Map(); | ||
for (const brandName of brandNames) { | ||
const oraclesWithID = addOraclesForBrand(baseId, brandName); | ||
oraclesByBrand.set(brandName, oraclesWithID); | ||
} | ||
return oraclesByBrand; | ||
}; | ||
|
||
export const pushPrices = async (price, brandIn, oraclesByBrand, round) => { | ||
await waitForBlock(1); | ||
// rotate which oracle is first. Use the round number | ||
const oracles = oraclesByBrand.get(brandIn); | ||
for (let i = 0; i < oracles.length; i += 1) { | ||
const offset = (i + round) % oracles.length; | ||
const oracle = oraclesByBrand.get(brandIn)[offset]; | ||
const oracleCmd = await agops.oracle( | ||
'pushPriceRound', | ||
'--price', | ||
price, | ||
'--oracleAdminAcceptOfferId', | ||
oracle.offerId, | ||
'--roundId', | ||
round, | ||
); | ||
await executeOffer(oracle.address, oracleCmd); | ||
} | ||
}; | ||
|
||
export const getPriceQuote = async price => { | ||
const path = `published.priceFeed.${price}-USD_price_feed`; | ||
const body = await getQuoteBody(path); | ||
return body.amountOut.value; | ||
}; | ||
|
||
export const agopsInter = (...params) => { | ||
const newParams = ['inter', ...params]; | ||
return executeCommand(agopsLocation, newParams); | ||
}; | ||
|
||
export const createBid = (price, addr, offerId) => { | ||
return agopsInter( | ||
'bid', | ||
'by-price', | ||
`--price ${price}`, | ||
`--give 1.0IST`, | ||
'--from', | ||
addr, | ||
'--keyring-backend test', | ||
`--offer-id ${offerId}`, | ||
); | ||
}; | ||
|
||
export const getLiveOffers = async addr => { | ||
const path = `published.wallet.${addr}.current`; | ||
const body = await getQuoteBody(path); | ||
return body.liveOffers; | ||
}; | ||
|
||
export const getAuctionCollateral = async index => { | ||
const path = `published.auction.book${index}`; | ||
const body = await getQuoteBody(path); | ||
return body.collateralAvailable.value; | ||
}; | ||
|
||
export const getVaultPrices = async index => { | ||
const path = `published.vaultFactory.managers.manager${index}.quotes`; | ||
const body = await getQuoteBody(path); | ||
return body.quoteAmount; | ||
}; | ||
|
||
export const bankSend = (addr, wanted) => { | ||
const chain = ['--chain-id', CHAINID]; | ||
const from = ['--from', VALIDATORADDR]; | ||
const testKeyring = ['--keyring-backend', 'test']; | ||
const noise = [...from, ...chain, ...testKeyring, '--yes']; | ||
|
||
return agd.tx('bank', 'send', VALIDATORADDR, addr, wanted, ...noise); | ||
}; | ||
|
||
export const getProvisionPoolMetrics = async () => { | ||
const path = `published.provisionPool.metrics`; | ||
return getQuoteBody(path); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"agoricProposal": { | ||
"sdk-generate": [ | ||
"vats/add-auction.js", | ||
"vats/upgradeVaults.js" | ||
], | ||
"type": "/agoric.swingset.CoreEvalProposal", | ||
"source": "subdir" | ||
}, | ||
"type": "module", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@agoric/synthetic-chain": "^0.1.0", | ||
"ava": "^5.3.1" | ||
}, | ||
"ava": { | ||
"concurrency": 1, | ||
"timeout": "2m", | ||
"files": [ | ||
"!submission" | ||
] | ||
}, | ||
"scripts": { | ||
"agops": "yarn --cwd /usr/src/agoric-sdk/ --silent agops" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
# Place here any test that should be run using the executed proposal. | ||
# The effects of this step are not persisted in further proposal layers. | ||
|
||
yarn ava ./*.test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm a little concerned at how much we're copying this around, but I think it can be solved better once it's in the agoric-3-proposals repo. That makes it easier to refactor between proposals and the
@agoric/synthetic-chain
lib, also in the repoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'll migrate the stable parts to
synthetic-chain
.