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

buyback test fixes #1960

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
60 changes: 12 additions & 48 deletions auxiliary/buyback-snx/cannonfile.test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,79 +8,43 @@ defaultValue = "10000000000000000"
defaultValue = "500000000000000000"

[provision.snx]
source = "mintable-token"
targetPreset = "permissionless-mint"
source = "mintable-token@permissionless-mint"
options.symbol = "SNX"
options.name = "Mintable SNX"
options.salt = "0xdeadbeef"
options.salt = "snx"

[provision.usd]
source = "mintable-token"
targetPreset = "permissionless-mint"
source = "mintable-token@permissionless-mint"
options.symbol = "USD"
options.name = "Mintable USD"
options.salt = "testing"
options.salt = "usd"

[setting.staleness_tolerance]
defaultValue = "60"

[setting.pyth_snx_feed_id]
defaultValue = "0x39d020f60982ed892abbcd4a06a276a9f9b7bfbce003204c110b6e488f502da3"

[provision.oracle_manager]
source = "oracle-manager:3.3.3-dev.249e185f"

[import.pyth]
source = "pyth"
source = "oracle-manager:3.3.5"
sourcePreset = "main"

[provision.pyth_erc7412_wrapper]
source = "pyth-erc7412-wrapper:3.3.3-dev.249e185f"
options.pythAddress = "<%= imports.pyth.contracts.Pyth.address %>"

# This registers a staleness node that looks to Pyth for a fresh enough price, or otherwise reverts with an ERC-7412 compatible error
# Latest Pyth Price
[invoke.registerPythSnxOracleNode]
# Latest Price
[invoke.registerConstantNode]
target = ["oracle_manager.Proxy"]
func = "registerNode"
args = [
5, # 5 = pyth aggregator type
"<%= defaultAbiCoder.encode(['address', 'bytes32', 'bool'], [imports.pyth_erc7412_wrapper.contracts.PythERC7412Wrapper.address, settings.pyth_snx_feed_id, false]) %>",
[]
8, # constant node type
"<%= defaultAbiCoder.encode(['int256'], [parseEther('10')]) %>",
[],
]
extra.snx_pyth_oracle_id.event = "NodeRegistered"
extra.snx_pyth_oracle_id.arg = 0

# Pyth Off-chain Lookup
[invoke.registerLookupSnxOracleNode]
target = ["oracle_manager.Proxy"]
func = "registerNode"
args = [
9, # 9 = PythOffchainLookupNode
"<%= defaultAbiCoder.encode(['address', 'bytes32', 'uint256'], [imports.pyth_erc7412_wrapper.contracts.PythERC7412Wrapper.address, settings.pyth_snx_feed_id, settings.staleness_tolerance]) %>",
[]
]
extra.snx_lookup_oracle_id.event = "NodeRegistered"
extra.snx_lookup_oracle_id.arg = 0

# Staleness Node
[invoke.registerSnxOracleNode]
target = ["oracle_manager.Proxy"]
func = "registerNode"
args = [
7, # 7 = staleness circuit breaker
"<%= defaultAbiCoder.encode(['uint256'], [settings.staleness_tolerance]) %>",
["<%= extras.snx_pyth_oracle_id %>", "<%= extras.snx_lookup_oracle_id %>"]
]
extra.snx_oracle_id.event = "NodeRegistered"
extra.snx_oracle_id.arg = 0

[contract.buyback_snx]
artifact = "contracts/BuybackSnx.sol:BuybackSnx"
args = [
"<%= settings.premium %>",
"<%= settings.snx_fee_share %>",
"<%= imports.oracle_manager.contracts.Proxy.address %>",
"<%= extras.snx_oracle_id %>",
"<%= extras.snx_pyth_oracle_id %>",
"<%= imports.snx.contracts.MintableToken.address %>",
"<%= imports.usd.contracts.MintableToken.address %>"
]
Expand Down
47 changes: 3 additions & 44 deletions auxiliary/buyback-snx/test/integration/BuybackSnx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,28 @@ import assert from 'assert/strict';
import assertBn from '@synthetixio/core-utils/utils/assertions/assert-bignumber';

import { ethers } from 'ethers';
import hre from 'hardhat';
import { bn, bootstrapBuyback } from './bootstrap';
import { findSingleEvent } from '@synthetixio/core-utils/utils/ethers/events';

const parseUnits = ethers.utils.parseUnits;

describe('BuybackSnx', function () {
const { getContract, user, owner } = bootstrapBuyback();

let Pyth: ethers.Contract;
let PythERC7412Wrapper: ethers.Contract;
let BuybackSnx: ethers.Contract;
let SnxToken: ethers.Contract;
let UsdToken: ethers.Contract;

let priceFeedId: string;

const snxPrice = bn(10);
const snxAmount = bn(100);
const usdAmount = bn(5000);
const premiumValue = bn(0.01);
const snxFeeShareRatio = bn(0.5);

const decimals = 8;
const price = parseUnits('10', decimals).toString();
const emaPrice = parseUnits('2', decimals).toString();

before('prepare environment', async () => {
const blockNumber = await hre.ethers.provider.getBlockNumber();
const timestamp = (await hre.ethers.provider.getBlock(blockNumber)).timestamp;

BuybackSnx = getContract('buyback_snx');
SnxToken = getContract('snx.MintableToken');
UsdToken = getContract('usd.MintableToken');
console.log('snx token address', SnxToken.address);
console.log('usd token address', UsdToken.address);

Pyth = getContract('pyth.Pyth');
PythERC7412Wrapper = getContract('pyth_erc7412_wrapper.PythERC7412Wrapper');
BuybackSnx = getContract('buyback_snx');

priceFeedId = '0x39d020f60982ed892abbcd4a06a276a9f9b7bfbce003204c110b6e488f502da3';
console.log('priceFeedId', priceFeedId.toString());

const resp = await Pyth.createPriceFeedUpdateData(
priceFeedId,
price,
1,
-decimals,
emaPrice,
1,
timestamp - 1,
0
);
console.log('Pyth.createPriceFeedUpdateData response', resp);
console.log('timestamp -1 ', timestamp - 1);

const fee = await Pyth['getUpdateFee(bytes[])']([resp]);
await Pyth.updatePriceFeeds([resp], { value: fee });

const priceUnsafe = await Pyth.getPriceUnsafe(priceFeedId);
console.log('Pyth.getPriceUnsafe(snxNodeId)', priceUnsafe.toString());
});

before('set up token balances', async () => {
Expand All @@ -85,7 +47,7 @@ describe('BuybackSnx', function () {
});
});

describe.skip('buyback', function () {
describe('buyback', function () {
let userAddress: string;
let userSnxBalanceBefore: any;
let userUsdBalanceBefore: any;
Expand All @@ -109,9 +71,6 @@ describe('BuybackSnx', function () {
});

it('buys snx for usd', async () => {
const snxPrice = await PythERC7412Wrapper.getLatestPrice(priceFeedId, 60);
console.log('PythERC7412Wrapper.getLatestPrice(snxNodeId, 60)', snxPrice.toString());

const premium = await BuybackSnx.getPremium();
console.log('premium', premium.toString());

Expand Down
2 changes: 0 additions & 2 deletions auxiliary/buyback-snx/test/integration/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { BuybackSnx } from '../generated/typechain';

interface Contracts {
buyback_snx: BuybackSnx;
'pyth.Pyth': ethers.Contract;
'pyth_erc7412_wrapper.PythERC7412Wrapper': ethers.Contract;
'snx.MintableToken': ethers.Contract;
'usd.MintableToken': ethers.Contract;
}
Expand Down
2 changes: 1 addition & 1 deletion markets/perps-market/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@synthetixio/router": "^3.3.0",
"@synthetixio/spot-market": "workspace:*",
"@synthetixio/wei": "^2.74.4",
"@usecannon/cli": "2.10.5",
"@usecannon/cli": "2.10.6-alpha.1",
"ethers": "^5.7.2",
"hardhat": "^2.19.0",
"solidity-docgen": "^0.6.0-beta.36",
Expand Down
2 changes: 1 addition & 1 deletion markets/perps-market/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"devDependencies": {
"@graphprotocol/graph-cli": "^0.61.0",
"@graphprotocol/graph-ts": "^0.31.0",
"@usecannon/cli": "2.10.5",
"@usecannon/cli": "2.10.6-alpha.1",
"ethers": "^5.7.2",
"matchstick-as": "^0.6.0",
"prettier": "^3.0.3"
Expand Down
2 changes: 1 addition & 1 deletion markets/spot-market/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@synthetixio/router": "^3.3.0",
"@synthetixio/wei": "^2.74.4",
"@types/node-fetch": "^2.6.9",
"@usecannon/cli": "2.10.5",
"@usecannon/cli": "2.10.6-alpha.1",
"ethers": "^5.7.2",
"hardhat": "^2.19.0",
"node-fetch": "^2.7.0",
Expand Down
2 changes: 1 addition & 1 deletion markets/spot-market/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"devDependencies": {
"@graphprotocol/graph-cli": "^0.61.0",
"@graphprotocol/graph-ts": "^0.31.0",
"@usecannon/cli": "2.10.5",
"@usecannon/cli": "2.10.6-alpha.1",
"ethers": "^5.7.2",
"matchstick-as": "^0.6.0",
"prettier": "^3.0.3"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@types/node": "^18.18.9",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@usecannon/cli": "2.10.5",
"@usecannon/cli": "2.10.6-alpha.1",
"eslint": "^8.53.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"lint-staged": "^15.0.2",
Expand Down
2 changes: 1 addition & 1 deletion protocol/synthetix/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"devDependencies": {
"@graphprotocol/graph-cli": "^0.61.0",
"@graphprotocol/graph-ts": "^0.31.0",
"@usecannon/cli": "2.10.5",
"@usecannon/cli": "2.10.6-alpha.1",
"ethers": "^5.7.2",
"matchstick-as": "^0.6.0",
"prettier": "^3.0.3"
Expand Down
2 changes: 1 addition & 1 deletion utils/common-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@typechain/hardhat": "^9.1.0",
"dotenv": "^16.3.1",
"hardhat": "^2.19.0",
"hardhat-cannon": "2.10.5",
"hardhat-cannon": "2.10.6-alpha.1",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-ignore-warnings": "^0.2.9",
Expand Down
2 changes: 1 addition & 1 deletion utils/core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/prompts": "^2.4.8",
"@usecannon/builder": "2.10.5",
"@usecannon/builder": "2.10.6-alpha.1",
"ethers": "^5.7.2",
"hardhat": "^2.19.0",
"mocha": "^10.2.0",
Expand Down
2 changes: 1 addition & 1 deletion utils/docgen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"docgen:contracts": "./docgen-contracts.sh"
},
"devDependencies": {
"@usecannon/builder": "2.10.5",
"@usecannon/builder": "2.10.6-alpha.1",
"handlebars": "^4.7.8",
"prettier": "^3.0.3",
"solidity-ast": "^0.4.52",
Expand Down
2 changes: 1 addition & 1 deletion utils/sample-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@synthetixio/router": "^3.3.0",
"ethers": "^5.7.2",
"hardhat": "^2.19.0",
"hardhat-cannon": "2.10.5",
"hardhat-cannon": "2.10.6-alpha.1",
"solidity-coverage": "^0.8.5"
}
}
Loading