Skip to content

Commit

Permalink
update on blend strategy and blend strategy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinsoza committed Nov 26, 2024
1 parent 06f9223 commit d54bb7e
Show file tree
Hide file tree
Showing 13 changed files with 419 additions and 371 deletions.
3 changes: 2 additions & 1 deletion apps/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"publish-addresses": "tsc && node dist/publish_addresses.js",
"test": "tsc && node dist/test.js",
"test-vault": "tsc && node dist/tests/testOnlyVault.js",
"test-blend": "tsc && node dist/tests/blend/test.js",
"test-blend-strategy": "tsc && node dist/tests/blend/test_strategy.js",
"test-blend-vault": "tsc && node dist/tests/blend/test_vault.js",
"test-dev": "tsc && node dist/tests/dev.js",
"test-two-strat-vault": "tsc && node dist/tests/testTwoStrategiesVault.js"
},
Expand Down
3 changes: 2 additions & 1 deletion apps/contracts/src/strategies/deploy_blend.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Asset, Networks, xdr } from "@stellar/stellar-sdk";
import { Address, Asset, nativeToScVal, Networks, xdr } from "@stellar/stellar-sdk";
import { AddressBook } from "../utils/address_book.js";
import {
airdropAccount,
Expand Down Expand Up @@ -47,6 +47,7 @@ export async function deployBlendStrategy(addressBook: AddressBook) {

const initArgs = xdr.ScVal.scvVec([
new Address("CCEVW3EEW4GRUZTZRTAMJAXD6XIF5IG7YQJMEEMKMVVGFPESTRXY2ZAV").toScVal(), //Blend pool on testnet!
nativeToScVal(0, {type: "u32"}) // ReserveId 0 is XLM
]);

const args: xdr.ScVal[] = [
Expand Down
232 changes: 0 additions & 232 deletions apps/contracts/src/tests/blend/test.ts

This file was deleted.

125 changes: 125 additions & 0 deletions apps/contracts/src/tests/blend/test_strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { Address, Keypair, nativeToScVal, scValToNative, xdr } from "@stellar/stellar-sdk";
import { AddressBook } from "../../utils/address_book.js";
import { airdropAccount, invokeContract } from "../../utils/contract.js";

const network = process.argv[2];
const addressBook = AddressBook.loadFromFile(network);

const purple = '\x1b[35m%s\x1b[0m';
const green = '\x1b[32m%s\x1b[0m';

export async function testBlendStrategy(user?: Keypair) {
// Create and fund a new user account if not provided
const newUser = Keypair.random();
console.log(green, '----------------------- New account created -------------------------')
console.log(green, 'Public key: ',newUser.publicKey())
console.log(green, '---------------------------------------------------------------------')

if (network !== "mainnet") {
console.log(purple, '-------------------------------------------------------------------')
console.log(purple, '----------------------- Funding new account -----------------------')
console.log(purple, '-------------------------------------------------------------------')
await airdropAccount(newUser);
}

try {
// Deposit XLM into Blend Strategy
console.log(purple, '---------------------------------------------------------------------------')
console.log(purple, '----------------------- Depositing XLM to the Strategy -----------------------')
console.log(purple, '---------------------------------------------------------------------------')
const depositParams: xdr.ScVal[] = [
nativeToScVal(1000_0_000_000, { type: "i128" }),
new Address(newUser.publicKey()).toScVal(),
]
const depositResult = await invokeContract(
'blend_strategy',
addressBook,
'deposit',
depositParams,
newUser,
false
);
console.log('🚀 « depositResult:', depositResult);
const depositResultValue = scValToNative(depositResult.returnValue);

console.log(green, '------------ XLM deposited to the Strategy ------------')
console.log(green, 'depositResult', depositResultValue)
console.log(green, '----------------------------------------------------')
}catch(e){
console.log('error', e)
}

// Wait for 1 minute
console.log(purple, '---------------------------------------------------------------------------')
console.log(purple, '----------------------- Waiting for 1 minute -----------------------')
console.log(purple, '---------------------------------------------------------------------------')
await new Promise(resolve => setTimeout(resolve, 100));

try {
// Withdrawing XLM from Blend Strategy
console.log(purple, '---------------------------------------------------------------------------')
console.log(purple, '----------------------- Withdrawing XLM from the Strategy -----------------------')
console.log(purple, '---------------------------------------------------------------------------')

const balanceScVal = await invokeContract(
'blend_strategy',
addressBook,
'balance',
[new Address(newUser.publicKey()).toScVal()],
newUser,
true
);
console.log('🚀 « balanceScVal:', balanceScVal);

const balance = scValToNative(balanceScVal.result.retval);
console.log('🚀 « balance:', balance);

const withdrawParams: xdr.ScVal[] = [
nativeToScVal(1000_0_000_000, { type: "i128" }),
new Address(newUser.publicKey()).toScVal(),
]
const withdrawResult = await invokeContract(
'blend_strategy',
addressBook,
'withdraw',
withdrawParams,
newUser,
false
);
const withdrawResultValue = scValToNative(withdrawResult.returnValue);

console.log(green, '------------ XLM withdrawed from the Strategy ------------')
console.log(green, 'withdrawResult', withdrawResultValue)
console.log(green, '----------------------------------------------------')
}catch(e){
console.log('error', e)
}

try {
// Harvest rewards from Blend Strategy
console.log(purple, '---------------------------------------------------------------------------')
console.log(purple, '----------------------- Harvesting from the Strategy -----------------------')
console.log(purple, '---------------------------------------------------------------------------')

const harvestParams: xdr.ScVal[] = [
new Address(newUser.publicKey()).toScVal(),
]
const harvestResult = await invokeContract(
'blend_strategy',
addressBook,
'harvest',
harvestParams,
newUser,
false
);
const harvestResultValue = scValToNative(harvestResult.returnValue);

console.log(green, '------------ BLND Harvested from the vault ------------')
console.log(green, 'harvestResult', harvestResultValue)
console.log(green, '----------------------------------------------------')
}catch(e){
console.log('error', e)
}
}

await testBlendStrategy();
Loading

0 comments on commit d54bb7e

Please sign in to comment.