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

Testnet deploy Dec-2024 #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@stellar/stellar-sdk": "^12.1.0",
"@stellar/stellar-sdk": "^13.0.0",
"dotenv": "^16.4.5"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
24 changes: 7 additions & 17 deletions public/testnet.contracts.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
{
"ids": {
"soroswap_adapter": "CDG7MKZQLLFJLDTZCYM4WJEFAJ5JMREJEVTBQRCWPRAPAOOWUY2VE5P4",
"aggregator": "CBO5CJWTH66QKYDCHBLC3IC44ZNEWDLDPRBJVPWH4CATR5SBERVTHZHF",
"phoenix_factory": "CC2YZDV2T6PDX7ZY5JC4JNBFLMKAKYCKPJ6DJ6AFTDPJH2WS3EYI3HHO",
"phoenix_multihop": "CBMFX6IFCIH4CRBXGIKCOIUJO5NBCPDZNIQJXF3F25M2JNRG2FXJXC4N",
"phoenix_adapter": "CC6GXBKZ4CYGMKH77RP5L7FMO45NHWVQIRVZE5VXGH7N6R4DQ7EPYT6W",
"deployer": "CDC7UZ5N4VL6O37YWS4XL5HLI3EMGMIRKDUX5C2Q6GUS7V4KL265SZED"
"deployer": "CBQZZ5YVQOGQ55WP5ILJX5LVR6FRUYQKLQDOMAF3A7EAE4SZ4MDWXE6A",
"soroswap_adapter": "CDXH5JQNZEHKDQONCA5TLAGPYOKYY4KXAOSMRMW7CPIPFP2IE5ZOB7K4",
"aggregator": "CB6E6HCE75WMRHFKE35SAGFINHXGUJ5OHD55JL74SYE2Y27IZGEWPAGP"
},
"hashes": {
"soroswap_adapter": "6e9897a0d084a6b0fb13bc719263ad808718b4417c12b6b314c1536297a46f71",
"aggregator": "de3c2cba30268f60caa470e6e3f3c14f34d16af0a3c19e01b728b3bd55a71991",
"phoenix_factory": "8bbcb24a54e5c1d0f8162cbea128d4b982886f52e58417a51d6ebab3d3744789",
"phoenix_multihop": "dded64a0535b44c856f93e860f3ef42f89d7b9479b7af341c34c3e81f48af550",
"phoenix_token": "52d85a1fc0df526ff84fcf9c45e810b1ed9780aaf2094c2d22dfd487f01ee644",
"phoenix_pool": "79d05d9245407f9447b4404646650bd20b7544a74a2da75a2bb234fa013b4b3f",
"phoenix_stake": "c678ba7a2a19c76f87cc827e45e103eab0febc8f269e4f31d22c8a5f095e7d8e",
"phoenix_adapter": "060d10e53779b685f6b2525fc6b1fb7f491601775a6f17fab319ac15e1e9c509",
"deployer": "c14be64defd72d2c01c78fc46206934a67844692ff17c974c5fd18a5f775cd7e",
"phoenix_stable": "ad0bdd69de996ba01b65c9d3c4190929d81b3a3c9fe2c75c19b21d558cab8bec"
"deployer": "6c83329a13014736589fbfd2af4ba99c080eab87ffc2cdf5d2df20b1c31e7448",
"soroswap_adapter": "b6b8bae178815d1a99acd28ab5898b1b753e7f460f6fad7382c9f371fcf65fbc",
"aggregator": "a4b62ddd5deca2ae411a5b0de42db075fde1c51e734180005d59ba04097cf85f"
}
}
}
99 changes: 52 additions & 47 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { randomBytes } from 'crypto';
import { phoenixSetup } from './protocols/phoenix/phoenix_setup.js';
import { updateAdapters } from './update_protocols.js';
import { AddressBook } from './utils/address_book.js';
import { airdropAccount, deployContract, installContract, invokeContract } from './utils/contract.js';
import {
airdropAccount,
deployContract,
installContract,
invokeContract,
} from './utils/contract.js';
import { config } from './utils/env_config.js';
import { TokensBook } from './utils/tokens_book.js';

Expand All @@ -20,23 +25,23 @@ export async function deployAndInitAggregator(addressBook: AddressBook) {
console.log('-------------------------------------------------------');
console.log('Deploying Adapters using the deployer');
console.log('-------------------------------------------------------');
console.log("** Soroswap Adapter");
console.log('** Soroswap Adapter');
await installContract('soroswap_adapter', addressBook, loadedConfig.admin);

const routerAddress = soroswapAddressBook.getContractId('router');

const initArgs = xdr.ScVal.scvVec([
xdr.ScVal.scvString("soroswap"), // protocol_id as ScVal string
new Address(routerAddress).toScVal() // protocol_address as ScVal address
xdr.ScVal.scvString('soroswap'), // protocol_id as ScVal string
new Address(routerAddress).toScVal(), // protocol_address as ScVal address
]);

const soroswapAdapterDeployParams: xdr.ScVal[] = [
new Address(loadedConfig.admin.publicKey()).toScVal(),
nativeToScVal(Buffer.from(addressBook.getWasmHash("soroswap_adapter"), "hex")),
nativeToScVal(Buffer.from(addressBook.getWasmHash('soroswap_adapter'), 'hex')),
nativeToScVal(randomBytes(32)),
xdr.ScVal.scvSymbol('initialize'),
initArgs
]
initArgs,
];

const response = await invokeContract(
'deployer',
Expand All @@ -46,54 +51,56 @@ export async function deployAndInitAggregator(addressBook: AddressBook) {
loadedConfig.admin
);

const soroswapAdapterAddress = scValToNative(response.returnValue)[0]
const soroswapAdapterAddress = scValToNative(response.returnValue)[0];
console.log('🚀 « soroswapAdapterAddress:', soroswapAdapterAddress);
// SAVE ADDRES IN ADDRESS BOOK
addressBook.setContractId("soroswap_adapter", soroswapAdapterAddress)
addressBook.setContractId('soroswap_adapter', soroswapAdapterAddress);

console.log('-------------------------------------------------------');
console.log('Deploying Aggregator');
console.log('-------------------------------------------------------');
console.log('Installing Aggregator Contract');
await installContract('aggregator', addressBook, loadedConfig.admin);

const adaptersVec = [
{
protocol_id: "soroswap",
protocol_id: 'soroswap',
address: new Address(addressBook.getContractId('soroswap_adapter')),
paused: false
paused: false,
},
];

const adaptersVecScVal = xdr.ScVal.scvVec(adaptersVec.map((adapter) => {
return xdr.ScVal.scvMap([
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol('address'),
val: adapter.address.toScVal(),
}),
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol('paused'),
val: nativeToScVal(adapter.paused),
}),
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol('protocol_id'),
val: xdr.ScVal.scvString(adapter.protocol_id),
}),
]);
}));
const adaptersVecScVal = xdr.ScVal.scvVec(
adaptersVec.map((adapter) => {
return xdr.ScVal.scvMap([
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol('address'),
val: adapter.address.toScVal(),
}),
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol('paused'),
val: nativeToScVal(adapter.paused),
}),
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol('protocol_id'),
val: xdr.ScVal.scvString(adapter.protocol_id),
}),
]);
})
);

const initAggregatorArgs = xdr.ScVal.scvVec([
new Address(loadedConfig.admin.publicKey()).toScVal(),
adaptersVecScVal
adaptersVecScVal,
]);

const soroswapAggregatorDeployParams: xdr.ScVal[] = [
new Address(loadedConfig.admin.publicKey()).toScVal(),
nativeToScVal(Buffer.from(addressBook.getWasmHash("aggregator"), "hex")),
nativeToScVal(Buffer.from(addressBook.getWasmHash('aggregator'), 'hex')),
nativeToScVal(randomBytes(32)),
xdr.ScVal.scvSymbol('initialize'),
initAggregatorArgs
]
initAggregatorArgs,
];

const response_aggregator = await invokeContract(
'deployer',
Expand All @@ -103,22 +110,22 @@ export async function deployAndInitAggregator(addressBook: AddressBook) {
loadedConfig.admin
);

const soroswapAggregatorAddress = scValToNative(response_aggregator.returnValue)[0]
const soroswapAggregatorAddress = scValToNative(response_aggregator.returnValue)[0];
console.log('🚀 « soroswapAggregatorAddress:', soroswapAggregatorAddress);
addressBook.setContractId("aggregator", soroswapAggregatorAddress)
addressBook.setContractId('aggregator', soroswapAggregatorAddress);

console.log("Aggregator initialized")
console.log('Aggregator initialized');

if (network != 'mainnet') {
console.log("Setting up Phoenix protocol")
// mocks
await phoenixSetup(loadedConfig, addressBook);
console.log("Updating adapters on aggregator.. adding Phoenix")
await updateAdapters(addressBook);
}
// if (network != 'mainnet') {
// console.log("Setting up Phoenix protocol")
// // mocks
// await phoenixSetup(loadedConfig, addressBook);
// console.log("Updating adapters on aggregator.. adding Phoenix")
// await updateAdapters(addressBook);
// }

// TODO: IF MAINNET, UPDATE PHOENIX ADAPTERS WITH MAINNET DEPLOYMENT ADDRESS
console.log("Aggregator setup complete")
console.log('Aggregator setup complete');
}

const network = process.argv[2];
Expand All @@ -129,9 +136,7 @@ const soroswapAddressBook = AddressBook.loadFromFile(
network,
`../../protocols/soroswap/${soroswapDir}`
);
const soroswapTokensBook = TokensBook.loadFromFile(
`./protocols/soroswap/${soroswapDir}`
);
const soroswapTokensBook = TokensBook.loadFromFile(`./protocols/soroswap/${soroswapDir}`);

const loadedConfig = config(network);

Expand Down
Loading