-
Notifications
You must be signed in to change notification settings - Fork 3
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
RepoContributor
committed
Jun 7, 2021
1 parent
ceda1e8
commit 92eebde
Showing
29 changed files
with
264 additions
and
112 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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getAddress, encodeUint, encodeBool } from '../utils' | ||
import ethSend from '../ethSend' | ||
|
||
export default async function castVote(params) { | ||
|
||
console.log('params', params); | ||
|
||
const { | ||
proposalId, | ||
support | ||
} = params; | ||
|
||
return ethSend({ | ||
address: getAddress('GOVERNANCE'), | ||
method: 'castVote(uint256,bool)', | ||
data: encodeUint(proposalId) + encodeBool(support) | ||
}); | ||
|
||
} |
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,18 @@ | ||
import { getAddress, encodeUint } from '../utils' | ||
import ethSend from '../ethSend' | ||
|
||
export default async function executeProposal(params) { | ||
|
||
console.log('params', params); | ||
|
||
const { | ||
proposalId | ||
} = params; | ||
|
||
return ethSend({ | ||
address: getAddress('GOVERNANCE'), | ||
method: 'executeProposal(uint256)', | ||
data: encodeUint(proposalId) | ||
}); | ||
|
||
} |
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,29 @@ | ||
import ethCall from '../ethCall' | ||
import { getAddress, encodeUint, abiDecodeOutput } from '../utils' | ||
|
||
export default function proposals(params) { | ||
|
||
const { | ||
proposal_id | ||
} = params; | ||
|
||
return ethCall({ | ||
address: getAddress('GOVERNANCE'), | ||
method: 'proposals(uint256)', | ||
data: encodeUint(proposal_id) | ||
}).then((result) => { | ||
return abiDecodeOutput(result, [ | ||
{name: 'id', type: 'uint256'}, | ||
{name: 'proposer', type: 'address'}, | ||
{name: 'startBlock', type: 'uint256'}, | ||
{name: 'endBlock', type: 'uint256'}, | ||
{name: 'expirationBlock', type: 'uint256'}, | ||
{name: 'forVotes', type: 'uint256'}, | ||
{name: 'againstVotes', type: 'uint256'}, | ||
{name: 'canceled', type: 'bool'}, | ||
{name: 'executed', type: 'bool'}, | ||
{name: 'expedited', type: 'bool'} | ||
]); | ||
}); | ||
|
||
} |
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,24 @@ | ||
import ethCall from '../ethCall' | ||
import { get } from 'svelte/store' | ||
import { user } from '../../stores/main' | ||
import { getAddress, encodeAddress } from '../utils' | ||
|
||
export default function getStakedBalance(params) { | ||
|
||
const _user = get(user); | ||
|
||
if (!_user) return 0n; | ||
|
||
return ethCall({ | ||
address: getAddress('GOVERNANCE'), | ||
method: 'balanceOf(address)', | ||
data: encodeAddress(_user) | ||
}).then((balance) => { | ||
// console.log('got balance', balance); | ||
if (balance == '0x') return 0n; | ||
return BigInt(balance); | ||
}).catch((e) => { | ||
console.log('balance err', e); | ||
}); | ||
|
||
} |
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,12 @@ | ||
import { getAddress } from '../utils' | ||
import ethCall from '../ethCall' | ||
|
||
export default function proposalCount(params) { | ||
|
||
return ethCall({ | ||
address: getAddress('GOVERNANCE'), | ||
method: 'proposalCount()', | ||
data: '' | ||
}).then(BigInt); | ||
|
||
} |
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,18 @@ | ||
import { getAddress, encodeUint } from '../utils' | ||
import ethSend from '../ethSend' | ||
|
||
export default async function stakeAmount(params) { | ||
|
||
console.log('params', params); | ||
|
||
const { | ||
amount | ||
} = params; | ||
|
||
return ethSend({ | ||
address: getAddress('GOVERNANCE'), | ||
method: 'releaseStaked(uint256)', | ||
data: encodeUint(amount) | ||
}); | ||
|
||
} |
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,34 @@ | ||
import { getAddress, encodeUint } from '../utils' | ||
import ethSend from '../ethSend' | ||
import getAllowance from '../token/getAllowance' | ||
import approve from '../token/approve' | ||
|
||
export default async function stakeAmount(params) { | ||
|
||
console.log('params', params); | ||
|
||
const { | ||
amount | ||
} = params; | ||
|
||
const GOVERNANCE_ADDRESS = getAddress('GOVERNANCE'); | ||
|
||
const allowance = await getAllowance({ | ||
address: getAddress('CAP'), | ||
spender: GOVERNANCE_ADDRESS | ||
}) | ||
|
||
console.log('allowance', allowance, amount, name, nonce); | ||
|
||
// approve if allowance not enough | ||
if (allowance < 100n * amount) { | ||
await approve({symbol: 'CAP', spender: GOVERNANCE_ADDRESS}); | ||
} | ||
|
||
return ethSend({ | ||
address: GOVERNANCE_ADDRESS, | ||
method: 'stakeToVote(uint256)', | ||
data: encodeUint(amount) | ||
}); | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
src/lib/getProductInfo.js → src/lib/products/getProductInfo.js
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,19 @@ | ||
import ethSend from '../ethSend' | ||
import { getAddress, encodeAddress, encodeUint } from '../utils' | ||
|
||
export default async function approve(params) { | ||
|
||
const { | ||
symbol, | ||
spender | ||
} = params | ||
|
||
return ethSend({ | ||
address: getAddress(symbol), | ||
method: 'approve(address,uint256)', | ||
data: encodeAddress(spender) + BigInt('0x' + 'F'.repeat(64)).toString() | ||
}).then((x,e) => { | ||
console.log('got x', x, e) | ||
}); | ||
|
||
} |
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
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
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
6 changes: 3 additions & 3 deletions
6
src/lib/getUserFreeMargin.js → src/lib/trading/getUserFreeMargin.js
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
Oops, something went wrong.