-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
1,763 additions
and
264 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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(); |
Oops, something went wrong.