-
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
1 parent
fb41cf0
commit 83e21b4
Showing
6 changed files
with
809 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { | ||
test, | ||
expect, | ||
} from 'vitest'; | ||
import { | ||
msgGetVault, | ||
msgGetVaults, | ||
msgGetVaultUserPosition, | ||
msgGetVaultUserPositions, | ||
msgBorrow, | ||
msgWithdraw, | ||
} from './lend'; | ||
|
||
test('it tests the form of the vault info message', () => { | ||
const inputVaultId = '1'; | ||
|
||
const output = { | ||
vault: { | ||
vault_id: inputVaultId, | ||
}, | ||
}; | ||
expect(msgGetVault(inputVaultId)).toStrictEqual(output); | ||
}); | ||
|
||
test('it tests the form of the multiple vaults info message', () => { | ||
const inputStartingPageNumber = 1; | ||
|
||
const output = { | ||
vaults: { | ||
starting_page: '1', | ||
}, | ||
}; | ||
expect(msgGetVaults(inputStartingPageNumber)).toStrictEqual(output); | ||
}); | ||
|
||
test('it tests the form of the vault user position message', () => { | ||
const inputVaultId = '1'; | ||
const permit = { | ||
params: { | ||
data: 'PERMIT_DATA', | ||
contract: 'CONTRACT', | ||
key: 'KEY', | ||
}, | ||
chain_id: 'CHAIN_ID', | ||
signature: { | ||
pub_key: { | ||
type: 'TYPE', | ||
value: 'VALUE', | ||
}, | ||
signature: 'SIGNATURE', | ||
}, | ||
}; | ||
|
||
const output = { | ||
with_permit: { | ||
permit, | ||
query: { | ||
position: { | ||
vault_id: inputVaultId, | ||
}, | ||
}, | ||
}, | ||
}; | ||
expect(msgGetVaultUserPosition(permit, inputVaultId)).toStrictEqual(output); | ||
}); | ||
|
||
test('it tests the form of the vaults user position message', () => { | ||
const inputVaultIds = ['1', '2']; | ||
const permit = { | ||
params: { | ||
data: 'PERMIT_DATA', | ||
contract: 'CONTRACT', | ||
key: 'KEY', | ||
}, | ||
chain_id: 'CHAIN_ID', | ||
signature: { | ||
pub_key: { | ||
type: 'TYPE', | ||
value: 'VALUE', | ||
}, | ||
signature: 'SIGNATURE', | ||
}, | ||
}; | ||
|
||
const output = { | ||
with_permit: { | ||
permit, | ||
query: { | ||
positions: { | ||
vault_ids: inputVaultIds, | ||
}, | ||
}, | ||
}, | ||
}; | ||
expect(msgGetVaultUserPositions(permit, inputVaultIds)).toStrictEqual(output); | ||
}); | ||
|
||
test('it test the form of the borrow message', () => { | ||
const input = { | ||
borrowAmount: 'BORROW_AMOUNT', | ||
maxBorrowFee: 'BORROW_FEE', | ||
vaultId: 'VAULT_ID', | ||
}; | ||
|
||
const output = { | ||
vault_action: { | ||
vault_id: input.vaultId, | ||
msg: { | ||
borrow: { | ||
amount: input.borrowAmount, | ||
max_fee: input.maxBorrowFee, | ||
}, | ||
}, | ||
}, | ||
}; | ||
expect(msgBorrow(input)).toStrictEqual(output); | ||
}); | ||
|
||
test('it test the form of the withdraw message', () => { | ||
const input = { | ||
withdrawAmount: 'WITHDRAW_AMOUNT', | ||
vaultId: 'VAULT_ID', | ||
}; | ||
|
||
const output = { | ||
vault_action: { | ||
vault_id: input.vaultId, | ||
msg: { withdraw: input.withdrawAmount }, | ||
}, | ||
}; | ||
expect(msgWithdraw(input.withdrawAmount, input.vaultId)).toStrictEqual(output); | ||
}); |
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,96 @@ | ||
import { AccountPermit } from '~/types/permit'; | ||
|
||
/** | ||
* message for the getting the vault info | ||
*/ | ||
const msgGetVault = (vaultId: string) => ({ | ||
vault: { | ||
vault_id: vaultId, | ||
}, | ||
}); | ||
|
||
/** | ||
* message for the getting multiple vaults info. | ||
* @param startingPage The data is paginated and returned | ||
* for the starting page and all pages after. Use 1 to query all vaults. | ||
*/ | ||
const msgGetVaults = (startingPage: number) => ({ | ||
vaults: { | ||
starting_page: startingPage.toString(), | ||
}, | ||
}); | ||
|
||
/** | ||
* message for the getting a user position | ||
*/ | ||
const msgGetVaultUserPosition = (permit: AccountPermit, vaultId: string) => ({ | ||
with_permit: { | ||
permit, | ||
query: { | ||
position: { | ||
vault_id: vaultId, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
/** | ||
* message for getting multiple user positions | ||
*/ | ||
const msgGetVaultUserPositions = (permit: AccountPermit, vaultIds: string[]) => ({ | ||
with_permit: { | ||
permit, | ||
query: { | ||
positions: { | ||
vault_ids: vaultIds, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
/** | ||
* message to borrow silk from a lend vault | ||
*/ | ||
const msgBorrow = ({ | ||
borrowAmount, | ||
maxBorrowFee, | ||
vaultId, | ||
}: { | ||
borrowAmount: string, | ||
maxBorrowFee: string, | ||
vaultId: string, | ||
}) => ({ | ||
vault_action: { | ||
vault_id: vaultId, | ||
msg: { | ||
borrow: { | ||
amount: borrowAmount, | ||
max_fee: maxBorrowFee, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
/** | ||
* message to withdraw collateral from a lend vault | ||
*/ | ||
const msgWithdraw = ( | ||
withdrawAmount: string, | ||
vaultId: string, | ||
) => ({ | ||
vault_action: { | ||
vault_id: vaultId, | ||
msg: { | ||
withdraw: withdrawAmount, | ||
}, | ||
}, | ||
}); | ||
|
||
export { | ||
msgGetVault, | ||
msgGetVaults, | ||
msgGetVaultUserPosition, | ||
msgGetVaultUserPositions, | ||
msgBorrow, | ||
msgWithdraw, | ||
}; |
Oops, something went wrong.